Search code examples
keyboardhid

What data can a HID device receive?


I am designing a USB keyboard with special capabilities. What information can such a HID device receive from the host?

Can I via USB:

  • Read data from a form on the screen?
  • Find out what OS the user is on?
  • Find out if there's been an error message?
  • Even 'know' what's going on visually on the screen, i.e. what program is selected or whether the program is windowed or fullscreen?

Thank you!


Solution

  • The device can't get any of this information from a standard driver that the operating system supplies because that would be a security issue. It can receive any information that your own driver or application sends it. There are many ways to communicate with it - your device could present multiple interfaces (which will appear as separate devices), multiple endpoints, or use the control channel. You will definitely need to study the spec, and I also found this tutorial helpful.

    I have done something similar and used the control channel to exchange feature data with a Windows application (over the standard Windows driver). On Windows, the API calls are HidD_SetFeature() and HidD_GetFeature().

    On the device side, my hardware ran embedded Linux and I used the GadgetFS library to create a user-mode driver - much easier to debug than a kernel driver.