简体   繁体   中英

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.

What I have on DirectInput side is:

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

On HID side:

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. the problem is that I have multiple controllers connected with the same VendorId and ProductId (they are the same brand)

is there a way to do this? to know the HID devicePath of an DirectInput InstanceId?

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 ). So, for each connected controller, I need to know all controllers info to be able to correctly configure each one on each emulator.

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.

I've already tried "Win32_PnPEntity" with "ManagementObjectSearcher" but had no luck

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. It will return HID device path.

In SharpDX it is represented by SharpDX.DirectInput.PropertyGuidAndPath struct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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