Introduction to Human Interface Devices
Human Interface Device (HID) is a specification that describes peripheral input devices that connect to computers over USB or Bluetooth. Manufacturers commonly use HID for devices such as gamepads, joysticks, and racing wheels. For more information, refer to Human Interface Devices (HID) (USB Implementers Forum).
The Input System directly supports HID on Windows, macOS, and the Universal Windows Platform (UWP). The Input System might support HID on other platforms, but not deliver input through HID-specific APIs. For example, on Linux, the Input System supports gamepad and joystick HIDs through Simple DirectMedia Layer (SDL), but doesn't support other HIDs.
The Input System handles HIDs in one of two ways:
- If the Input System has a layout for the specific HID, it uses that layout.
- If the Input System doesn't have a layout for the HID, it generates one.
Auto-generated layouts
By default, the Input System creates layouts and device representations for any HID that reports its usage as GenericDesktop/Joystick, GenericDesktop/Gamepad, or GenericDesktop/MultiAxisController. For more information, refer to HID Usage Tables (USB Implementers Forum). To change the list of supported usages, set HIDSupport.supportedHIDUsages.
When the Input System generates a layout for an HID, it always represents the device as a joystick, using the Joystick class. The Input System builds the layout as follows:
- The first elements with a reported HID usage of
GenericDesktop/XandGenericDesktop/Ytogether form the joystick'sstickcontrol. - The Input System adds controls for all further HID axis or button elements, and names each control after its HID usage.
- The Input System assigns the first control with an HID usage of
Button/Button 1to the joystick'striggercontrol.
The way HIDs meet the HID standard varies, so generated layouts might lead to controls that don't work as expected. For example, while the layout builder can identify hat switches and D-pads, it often has to assume which direction each one represents. The same applies to individual buttons, because HID doesn't usually give buttons a meaning.
To fix an HID that doesn't work as expected, add a custom layout. The Input System uses the custom layout instead of generating one. For more information, refer to Create a custom device layout.
HID in the Unity Editor
Every HID comes with a device descriptor. To view an HID's descriptor, open the device in the Input Debugger window, then select HID Descriptor.
The HID descriptor identifies the type of device with the following information:
- Entry numbers in the HID usage tables.
- A list of all controls on the device, along with their data ranges and usages.
HID output
HIDs can support output. For example, they can toggle lights or force feedback motors on a gamepad. The Input System controls output by sending HID output report commands to a device. Output reports use device-specific data formats.
To use HID output reports, call InputDevice.ExecuteCommand to send a command struct with the typeStatic property set to HIDO to a device. The command struct contains the device-specific data sent out to the HID.