Search code examples
windowswinapikeyboardkeyhid

How to convert from a HID Usage ID to a Virtual Key Code in Windows OS?


Is there a way to convert a USB HID Usage ID to a Virtual Key code in Windows OS?

for example,

HID Usage ID 0x04 ---> Virtual Key is 0x41 (this is key A)

HID Usage ID 0x91 ---> Virtual Key is 0xE9 (this is a OEM specific key)

HID Usage ID 0x87 ---> Virtual Key is 0xC1 (this is a Reserved key code)

...

I just found a virtual keys code table, but I can't find a translation table or a way to translate it efficiently.


Solution

  • There is no API to translate between HID Usage IDs and virtual key codes. The translation is performed by the device driver.

    The Usage IDs for keyboards are published on http://usb.org in the HID Usage Tables specification (Chapter 10 "Keyboard/Keypad Page (0x07)").