bernspedras
bernspedras

Reputation: 121

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

Upvotes: 2

Views: 851

Answers (2)

DJm00n
DJm00n

Reputation: 1441

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.

Upvotes: 1

bernspedras
bernspedras

Reputation: 121

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)
}

Upvotes: 1

Related Questions