简体   繁体   English

如何将 map DirectInput (sharpDX) 设备与其对应的 HID (C#)

[英]How to map DirectInput (sharpDX) device to it's corresponding HID (C#)

What I need is a way to find out the curresponding HID of a SharpDX.DirectInput DeviceInstance.我需要的是一种找出 SharpDX.DirectInput DeviceInstance 的相应 HID 的方法。

What I have on DirectInput side is:我在 DirectInput 方面拥有的是:

ProductId -> 00060079-0000-0000-0000-504944564944 (always the same)
InstanceId -> 8e3d89c0-6436-11e9-8004-444553540000 (dynamic / changes every time PC starts)

On HID side:在 HID 方面:

VendorID=0x0079
ProductID=0x0006,
Version=263,
DevicePath=\\?\hid#vid_0079&pid_0006#8&1ec29a1c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

I can see that the HID vendorId and ProductId are used to build the DirectInput ProductId.我可以看到 HID vendorId 和 ProductId 用于构建 DirectInput ProductId。 the problem is that I have multiple controllers connected with the same VendorId and ProductId (they are the same brand)问题是我有多个控制器连接到相同的 VendorId 和 ProductId(它们是同一个品牌)

is there a way to do this?有没有办法做到这一点? to know the HID devicePath of an DirectInput InstanceId?知道 DirectInput InstanceId 的 HID devicePath?

For context:对于上下文:

I'm writing a software to automatic configure many controllers on many emulators for my custom arcade machine.我正在编写一个软件来为我的自定义街机机器自动配置许多模拟器上的许多控制器。 The emulators use a combination of DirectInput/XInput/DSUClient ( https://github.com/v1993/cemuhook-protocol ).模拟器使用 DirectInput/XInput/DSUClient ( https://github.com/v1993/cemuhook-protocol ) 的组合。 So, for each connected controller, I need to know all controllers info to be able to correctly configure each one on each emulator.因此,对于每个连接的 controller,我需要知道所有控制器信息才能在每个仿真器上正确配置每个控制器。

For now as a (very bad) workaround, i'm listening to inputs from DirectInput separeted from HID and when the reading occurs I know that the HID device is the DirectInput device because they occured (almost) on the same time.现在作为一个(非常糟糕的)解决方法,我正在监听与 HID 分离的 DirectInput 的输入,当读取发生时,我知道 HID 设备是 DirectInput 设备,因为它们(几乎)同时发生。

I've already tried "Win32_PnPEntity" with "ManagementObjectSearcher" but had no luck我已经用“ManagementObjectSearcher”尝试过“Win32_PnPEntity”但没有运气

I ended up finding the solution...我最终找到了解决方案...

DirectInput directInput = new DirectInput();
foreach (var deviceInstance in directInput.GetDevices())
{
    var joystick = new Joystick(directInput, deviceInstance.InstanceGuid);
    Console.WriteLine(joystick.Properties.InterfacePath)
}

There is DIPROP_GUIDANDPATH property that could be requested via IDirectInputDevice8::GetProperty API.可以通过IDirectInputDevice8::GetProperty API 请求DIPROP_GUIDANDPATH属性。 It will return HID device path.它将返回 HID 设备路径。

In SharpDX it is represented by SharpDX.DirectInput.PropertyGuidAndPath struct.在 SharpDX 中,它由SharpDX.DirectInput.PropertyGuidAndPath结构表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM