How to get the pid/vid/device name of the device?
Closed this issue Β· 9 comments
This package is great for me, thank you very much! I have only one question, how to get the pid/vid/device name of the device?
I'm no expert but I think XINPUT doesn't provide VID/PID by design. It might be possible to cross-correlate it with DirectInput.
That said, there is XINPUT_CAPABILITIES and its Subtypes : https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes that could be useful ? Idk what you are trying to achieve but I'm guessing you want to change something based on which 'type' of controller is connected.
I've implemented XInputGetCapabilities via GetCapabilities()
{
Type: 'XINPUT_DEVTYPE_GAMEPAD',
SubType: 'XINPUT_DEVSUBTYPE_GAMEPAD',
Flags: 12
}
SubType list : https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes
Flags list : https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities#members
I've added 2 fn to list and identify device
console.log ( await XInput.identify.XInputDevices() )
[
{
guid: '{745a17a0-74d3-11d0-b6fe-00a0c90f57da}',
vid: '045E',
pid: '028E',
interfaces: [ 'USB', 'HID' ],
manufacturer: 'Microsoft Corp.',
name: 'Xbox360 Controller'
}
]
and
console.log ( await XInput.identify.knownDevices() )
[
{
manufacturer: 'Sony Corp.',
name: 'DualShock 4 USB Wireless Adaptor',
vid: '054C',
pid: '0BA0',
interfaces: [ 'USB', 'HID' ],
guid: [
'{745a17a0-74d3-11d0-b6fe-00a0c90f57da}',
'{36fc9e60-c465-11cf-8056-444553540000}',
'{4d36e96c-e325-11ce-bfc1-08002be10318}'
],
xinput: false
},
{
manufacturer: 'Microsoft Corp.',
name: 'Xbox360 Controller',
vid: '045E',
pid: '028E',
interfaces: [ 'USB', 'HID' ],
guid: [
'{745a17a0-74d3-11d0-b6fe-00a0c90f57da}',
'{d61ca365-5af4-4486-998b-9db4734c6ca3}'
],
xinput: true
}
]
NB: There is also node-hid where you can list all HID devices connected
I can't do better than that π
I'm no expert but I think XINPUT doesn't provide VID/PID by design. It might be possible to cross-correlate it with DirectInput.
That said, there is XINPUT_CAPABILITIES and its Subtypes : https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes that could be useful ? Idk what you are trying to achieve but I'm guessing you want to change something based on which 'type' of controller is connected.
Thank you for your reply and your work!
I was already using node-hid before using xinput-ffi, but my controller is an x-input device (non-standard hid device) and cannot directly communicate with hid.
So we thought of a way of hacking - notify the controller to switch to d-input mode (standard hid device) for communication through a specific vibration value.
However, xinput-ffi can correctly send vibration commands to the controller, everything is as expected when using a single controller, but if there are multiple controllers, I cannot distinguish which is my controller, this is my problem.
I've implemented XInputGetCapabilities via GetCapabilities()
{ Type: 'XINPUT_DEVTYPE_GAMEPAD', SubType: 'XINPUT_DEVSUBTYPE_GAMEPAD', Flags: 12 }SubType list : https://docs.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes
Flags list : https://docs.microsoft.com/en-us/windows/win32/api/xinput/ns-xinput-xinput_capabilities#membersI've added 2 fn to list and identify device
console.log ( await XInput.identify.XInputDevices() ) [ { guid: '{745a17a0-74d3-11d0-b6fe-00a0c90f57da}', vid: '045E', pid: '028E', interfaces: [ 'USB', 'HID' ], manufacturer: 'Microsoft Corp.', name: 'Xbox360 Controller' } ]and
console.log ( await XInput.identify.knownDevices() ) [ { manufacturer: 'Sony Corp.', name: 'DualShock 4 USB Wireless Adaptor', vid: '054C', pid: '0BA0', interfaces: [ 'USB', 'HID' ], guid: [ '{745a17a0-74d3-11d0-b6fe-00a0c90f57da}', '{36fc9e60-c465-11cf-8056-444553540000}', '{4d36e96c-e325-11ce-bfc1-08002be10318}' ], xinput: false }, { manufacturer: 'Microsoft Corp.', name: 'Xbox360 Controller', vid: '045E', pid: '028E', interfaces: [ 'USB', 'HID' ], guid: [ '{745a17a0-74d3-11d0-b6fe-00a0c90f57da}', '{d61ca365-5af4-4486-998b-9db4734c6ca3}' ], xinput: true } ]NB: There is also node-hid where you can list all HID devices connected
I can't do better than that π
When I plug in the Xbox controller, XInput.identify.XInputDevices
can return the expected value correctly, but when I plug in my controller, I seem to get an error:
devices: true,false,false,false
TypeError: Cannot read property 'controller' of undefined
at Object.listXInput (E:\Project\2020\SwitchAPP\dev-branche\node_modules\xinput-ffi\lib\PNPEntity\list.cjs:107:34)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async Object.XInputDevices (E:\Project\2020\SwitchAPP\dev-branche\node_modules\xinput-ffi\lib\xinput.cjs:425:14)
Code:
const XInput = require("xinput-ffi");
let devices = XInput.sync.listConnected();
console.log('devices: ' + devices);
XInput.identify.XInputDevices().then((x) => {
console.log(x);
}).catch((e) => {
console.log(e);
})
An oversight from my part. Sorry for the inconvenience. I've updated the package should be good now π.
Sorry for the late.
That error has been resolved, thanks. But I still donβt know how to associate the object returned in XInput.identify.XInputDevices with the gamepadIndex in XInput.listConnected.
I have given up using this way, but I still appreciate it π.
I found a way to query XInput device Vid and Pid on StackOverflow and it does work.π
But I don't know how to convert it into nodejs code, is it possible to include it in node-xinput-ffi
?
Wow very interesting stuff π.
It seemed simple enough ^^ but ... (C/C++ noob here) it is my understanding that this hidden function can't be accessed by name but only by ordinal (108).
Which I don't think node-ffi / node-ffi-napi can do.
I found it mentioned only in node-ffi#398
without answers.
Using by name XInputGetCapabilitiesEx
or ordinal 108 ffi just crashes of course.
Maybe a solution is to make a dll wrapper to expose it by name π€.
FYI v3.0.0 supports XInputGetCapabilitiesEx
(and others hidden fn)