0
\$\begingroup\$

I'm using RawInput for device management, in a project that I have been working on for some time. It works great, really, but...

After some hardware changes on my development system, including the addition of a second Wacom device, I'm having difficulty getting RawInput to enumerate the default mouse and keyboard input devices without going in and plugging hard values into the enumeration code.

When I call GetRawInputDeviceList and sort through the device instances based on their RawInput DeviceType, I have 5 keyboard devices and 6 mice, along with a slew of non-specific HID devices. Usually, the first keyboard device returned is the real default system keyboard -- but not always. Adding or removing USB devices between application runs almost always breaks it.

Digging deeper into the enumerated device instances, I thought that examining the RawInputDeviceInformation structure would help. For some devices, especially older input devices, there's a value that allows you to identify which device instance is a real physical device and not one of those phantom/pseudo devices. DeviceInformation structures on keyboard device instances all report a differing number of keys, with all the other significant values -- vendor, usage page, usage, etc. being identical. Unsurprisingly, the reported number of keys doesn't even reflect the actual number of physical keys on the keyboard.

DirectInput identifies the default system mouse and keyboard, and although it's based on RawInput, does it use RawInput to achieve this? Switching away from RawInput is not an option for me because of the other devices I am operating with it (Wacom, Logitech G19 etc). Any advice on how to straighten this out would be gratefully received, with thanks!

\$\endgroup\$
1
  • \$\begingroup\$ If all possible device instances were created, including the phantom devices, the identity of physical devices could be known once keys are being pressed and the mouse moved, since they would generate a WM_INPUT message but that solution relies on the user. \$\endgroup\$
    – ROGRat
    May 13 '18 at 18:46
0
\$\begingroup\$

I solved this problem finally. To get the default mouse and/or keyboard on systems that have more than one such device installed requires the PageOnly member of RawInputDeviceFlags.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.