type hid -
into the terminal, then type/paste commands to send to the binary. Use Ctrl+D to signal end of stream to the binary (EOF).
This mode can be also used from an app to send HID events. For an example, see the cts test case at: InputTestCase.java
When using another program to control hid in interactive mode, registering a new input device (for example, a bluetooth joystick) should be the first step. After the device is added, you need to wait for the onInputDeviceAdded (see InputDeviceListener) notification before issuing commands to the device. Failure to do so will cause missed events and inconsistent behaviour. In the current implementation of the hid command, the hid binary will wait for the file descriptor to the uhid node to send the UHID_START and UHID_OPEN signals before returning. However, this is not sufficient. These signals only notify the readiness of the kernel driver, but do not take into account the inputflinger framework.
type hid <filename>
, and the file will be used an an input to the binary. You must add a sufficient delay after a "register" command to ensure device is ready. The interactive mode is the recommended method of communicating with the hid binary.
All of the input commands should be in pseudo-JSON format as documented below. See examples here.
The file can have multiple commands one after the other (which is not strictly legal JSON format, as this would imply multiple root elements).
register
Register a new uhid deviceField | Type | Description |
---|---|---|
id | integer | Device id |
command | string | Must be set to "register" |
name | string | Device name |
vid | 16-bit integer | Vendor id |
pid | 16-bit integer | Product id |
descriptor | byte array | USB HID report descriptor |
Device ID is used for matching the subsequent commands to a specific device to avoid ambiguity when multiple devices are registered.
USB HID report descriptor should be generated according the the USB HID spec and can be checked by reverse parsing using a variety of tools, for example usbdescreqparser.
Example:
{ "id": 1, "command": "register", "name": "Odie (Test)", "vid": 0x18d1, "pid": 0x2c40, "descriptor": [0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x09, 0x0a, 0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x04, 0x00, 0x0a, 0x05, 0x00, 0x0a, 0x07, 0x00, 0x0a, 0x08, 0x00, 0x0a, 0x0e, 0x00, 0x0a, 0x0f, 0x00, 0x0a, 0x0d, 0x00, 0x05, 0x0c, 0x0a, 0x24, 0x02, 0x0a, 0x23, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x0b, 0x81, 0x02, 0x75, 0x01, 0x95, 0x01, 0x81, 0x03, 0x05, 0x01, 0x75, 0x04, 0x95, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x66, 0x14, 0x00, 0x09, 0x39, 0x81, 0x42, 0x66, 0x00, 0x00, 0x09, 0x01, 0xa1, 0x00, 0x09, 0x30, 0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x05, 0x02, 0x09, 0xc5, 0x09, 0xc4, 0x15, 0x00, 0x26, 0xff, 0x00, 0x35, 0x00, 0x46, 0xff, 0x00, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0x85, 0x02, 0x05, 0x08, 0x0a, 0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x03, 0x00, 0x0a, 0x04, 0x00, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95, 0x01, 0x91, 0x03, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x05, 0x01, 0x09, 0x06, 0xa1, 0x02, 0x05, 0x06, 0x09, 0x20, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81, 0x02, 0x06, 0xbc, 0xff, 0x0a, 0xad, 0xbd, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0xc0] }
delay
Add a delay to command processingField | Type | Description |
---|---|---|
id | integer | Device id |
command | string | Must be set to "delay" |
duration | integer | Delay in milliseconds |
Example:
{ "id": 1, "command": "delay", "duration": 10 }
report
Send a report to the HID deviceField | Type | Description |
---|---|---|
id | integer | Device id |
command | string | Must be set to "report" |
report | byte array | Report data to send |
Example:
{ "id": 1, "command": "report", "report": [0x01, 0x01, 0x80, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x00] }
To send a button press event on a joystick device:
getevent
utility can used to print out the key events for debugging purposes.