如何将 DirectInput (sharpDX) 设备映射到它对应的 HID (C#)

问题描述

我需要的是一种找出 SharpDX.DirectInput DeviceInstance 的当前 HID 的方法

我在 DirectInput 方面拥有的是:

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

在 HID 方面:

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

我可以看到 HID vendorId 和 ProductId 用于构建 DirectInput ProductId。问题是我有多个控制器连接到相同的 vendorId 和 ProductId(它们是同一个品牌)

有没有办法做到这一点?想知道 DirectInput InstanceId 的 HID devicePath?

上下文:

我正在编写一个软件,用于在许多模拟器上为我的自定义街机自动配置许多控制器。模拟器使用 DirectInput/XInput/DSUClient (https://github.com/v1993/cemuhook-protocol) 的组合。因此,对于每个连接的控制器,我需要知道所有控制器信息,以便能够在每个模拟器上正确配置每个控制器。

现在作为(非常糟糕的)解决方法,我正在收听与 HID 分离的 DirectInput 的输入,当读取发生时,我知道 HID 设备是 DirectInput 设备,因为它们(几乎)同时发生。

我已经用“ManagementObjectSearcher”尝试过“Win32_PnPEntity”,但没有成功

解决方法

我最终找到了解决方案...

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