Author Topic: How does host identify if a HID is mouse, keyboard or gamepad?  (Read 4691 times)

matrixofdynamism

  • Member
  • ***
  • Posts: 12
How does host identify if a HID is mouse, keyboard or gamepad?
« on: January 06, 2017, 07:51:24 am »
How does window (or any USB host) identify that the reports from a HID device are for mouse movement, keyboard key strokes or gamepad button presses? Is it only from PID/VID? If we are designing an embedded host, how will it know if the connected device is mouse, keyboard or gamepad?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: How does host identify if a HID is mouse, keyboard or gamepad?
« Reply #1 on: January 06, 2017, 04:20:28 pm »
See the HID usage tables for values that identify specific functions.

http://www.usb.org/developers/hidpage/

Bret

  • Frequent Contributor
  • ****
  • Posts: 68
Re: How does host identify if a HID is mouse, keyboard or gamepad?
« Reply #2 on: January 11, 2017, 01:10:11 pm »
It also turns out that many HID devices are somewhat ambiguous in what you would call them, particularly in the virtual world of USB.  For example, I have devices that are combination keyboards and mice, but some of the keys that are physically on the keyboard are reported though USB as if they were part of the mouse.  For example, the "media keys" (Volume control, Play/Pause, etc.), if the keyboard has them, are considered in USB to be Consumer Control Inputs, not Keys on the Keyboard.  They are ALWAYS reported via a different mechanism in USB (at a minimum a different Report ID), and the mechanism in USB can be associated with the mouse instead of the keyboard.  A similar situation occurs with the Power/Sleep/Wakeup keys (if your keyboard has them) -- they are considered System Control Inputs in USB, not Keyboard Keys and not Consumer Control Inputs, either.

The only way you can really tell what an HID device does (for example, how many buttons and wheels a mouse has) is by looking at the HID level (the HID Report Descriptor(s)).  You really can't tell by simply looking at the USB level.  Also, there are a lot more types of HID devices than keyboards, mice, and joysticks/gamepads.
« Last Edit: January 11, 2017, 01:12:17 pm by Bret »