加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

ue4 Windows RawInput Plugin

发布时间:2020-12-14 02:37:10 所属栏目:Windows 来源:网络整理
导读:链接:https://zhuanlan.zhihu.com/p/55084002 最近在做一个模拟飞行的项目时,需要外接飞行摇杆,我使用了官方的Windows Rawinput Plugin,但在使用的时候报了一个HIDStatusBufferTooSmall的warning,网上并没有查到任何信息,但最终我还是找到了解决的办法

链接:https://zhuanlan.zhihu.com/p/55084002

最近在做一个模拟飞行的项目时,需要外接飞行摇杆,我使用了官方的Windows Rawinput Plugin,但在使用的时候报了一个HIDStatusBufferTooSmall的warning,网上并没有查到任何信息,但最终我还是找到了解决的办法。

  1. 此插件只支持同时按下两个按键,当大于2个的时候就会报HIDStatusBufferTooSmall的错误,我们找到插件的源代码,在RawInputWindows.cpp的ParseInputData方法内修改一下提高同时按压键数就可以了,我直接给赋值了40,就是说同时可以按压40个键,当然你也可以修改为其他的数值。
    if (HIDStatus != HIDP_STATUS_SUCCESS)
    	{
    		UE_LOG(LogRawInputWindows,Warning,TEXT("Failed to read button caps: %x:%s"),(int32)HIDStatus,*GetErrorString(HIDStatus));
    	}
    	else
    	{
    		//const int32 NumberOfButtons = ButtonCapsBuffer[0].Range.UsageMax - ButtonCapsBuffer[0].Range.UsageMin + 1;
    		/*当摇杆同时按下多个键时,上边的会出错,报HIDStatusBufferTooSmall错误,所以直接赋值*/
    		const int32 NumberOfButtons = 40;
    		const uint32 ButtonDataBufferSize = NumberOfButtons * sizeof(uint16);
    		uint16* ButtonDataBuffer = (uint16*)FMemory_Alloca(ButtonDataBufferSize);
    		FMemory::Memzero(ButtonDataBuffer,ButtonDataBufferSize);
    
    		uint32 UsageNumButtonCaps = NumberOfButtons;
    
    
    		HIDStatus = DLLPointers.HidP_GetUsages(HIDP_REPORT_TYPE::HidP_Input,ButtonCapsBuffer[0].UsagePage,ButtonDataBuffer,&UsageNumButtonCaps,InPreParsedData,(PCHAR)InRawInputDataBuffer->data.hid.bRawData,InRawInputDataBuffer->data.hid.dwSizeHid);
    		if (HIDStatus != HIDP_STATUS_SUCCESS)
    		{
    			UE_LOG(LogRawInputWindows,TEXT("Failed to read button data: %x:%s"),*GetErrorString(HIDStatus));
    		
    

      

    2.插件修改了源码后需要重新编译,我的ue4是launcher下载的,我们需要将该插件内Intermediate和Binaries文件夹删除,再打开项目就会提示缺少rawinput.dll,然后点击确定重新编译。

    3.当插件在ue4的插件目录时,无论如何都不能编译成功,最终我将该插件放到了项目的Plugins目录中,编译成功。

    4.还有一种情况,就是默认该插件只有8个axis和20个button,我需要更多地button和axis,需要把源码内的button和axis增加至你需要的个数,然后重新编译,这个比较简单,就不一一说了,只需要小心一些,修改好几个文件呢。特别的,就是RawInputWindows.h中修改两个宏定义。

  2. #include "hidsdi.h"
    
    #define MAX_NUM_CONTROLLER_BUTTONS 40   //修改为你需要的数目  最大button数目
    #define MAX_NUM_CONTROLLER_ANALOG 8    //最大axis数目
    #define RAW_INPUT_ERROR (uint32)(-1)
    

      其他的基本都是这样的:

  3. const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button19("GenericUSBController_Button19");
    const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button20("GenericUSBController_Button20");
    //上边两个是原有的,下边的是添加的  代码一样,只需要该id就行
    const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button21("GenericUSBController_Button21");
    const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button22("GenericUSBController_Button22");
    const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button23("GenericUSBController_Button23");
    const FGamepadKeyNames::Type FRawInputKeyNames::GenericUSBController_Button24("GenericUSBController_Button24");
    

      

    5.在ue4中注册外接设备时,需要在ue4中设置以下内容

    ? ? ? ? ? ? ? ? ? ?

    在VendorID中填写外设的VID,在ProductID填写PID,外设的vid和pid在设备管理器中查看。

    以上边的为例,你需要在ue4中填写0x1038和0x1392。

    以上就是所有有关WindowsRawinput的内容。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读