| 1 | # Usage |
| 2 | ## Two options to use the uinput command: |
| 3 | ### 1. Interactive through stdin: |
| 4 | type `uinput -` into the terminal, then type/paste commands to send to the binary. |
| 5 | Use Ctrl+D to signal end of stream to the binary (EOF). |
| 6 | |
| 7 | This mode can be also used from an app to send uinput events. |
| 8 | For an example, see the cts test case at: [InputTestCase.java][2] |
| 9 | |
| 10 | When using another program to control uinput in interactive mode, registering a |
| 11 | new input device (for example, a bluetooth joystick) should be the first step. |
| 12 | After the device is added, you need to wait for the _onInputDeviceAdded_ |
| 13 | (see [InputDeviceListener][1]) notification before issuing commands |
| 14 | to the device. |
| 15 | Failure to do so will cause missed events and inconsistent behavior. |
| 16 | |
| 17 | ### 2. Using a file as an input: |
| 18 | type `uinput <filename>`, and the file will be used an an input to the binary. |
| 19 | You must add a sufficient delay after a "register" command to ensure device |
| 20 | is ready. The interactive mode is the recommended method of communicating |
| 21 | with the uinput binary. |
| 22 | |
| 23 | All of the input commands should be in pseudo-JSON format as documented below. |
| 24 | See examples [here][3]. |
| 25 | |
| 26 | The file can have multiple commands one after the other (which is not strictly |
| 27 | legal JSON format, as this would imply multiple root elements). |
| 28 | |
| 29 | ## Command description |
| 30 | |
| 31 | 1. `register` |
| 32 | Register a new uinput device |
| 33 | |
| 34 | | Field | Type | Description | |
| 35 | |:-------------:|:-------------:|:-------------------------- | |
| 36 | | id | integer | Device id | |
| 37 | | command | string | Must be set to "register" | |
| 38 | | name | string | Device name | |
| 39 | | vid | 16-bit integer| Vendor id | |
| 40 | | pid | 16-bit integer| Product id | |
| 41 | | bus | string | Bus that device should use | |
| 42 | | configuration | int array | uinput device configuration| |
| 43 | | ff_effects_max| integer | ff_effects_max value | |
| 44 | | abs_info | array | ABS axes information | |
| 45 | |
| 46 | Device ID is used for matching the subsequent commands to a specific device |
| 47 | to avoid ambiguity when multiple devices are registered. |
| 48 | |
| 49 | Device bus is used to determine how the uinput device is connected to the host. |
| 50 | The options are "usb" and "bluetooth". |
| 51 | |
| 52 | Device configuration is used to configure uinput device. "type" field provides the UI_SET_* |
| 53 | control code, and data is a vector of control values to be sent to uinput device, depends on |
| 54 | the control code. |
| 55 | |
| 56 | | Field | Type | Description | |
| 57 | |:-------------:|:-------------:|:-------------------------- | |
| 58 | | type | integer | UI_SET_ control type | |
| 59 | | data | int array | control values | |
| 60 | |
| 61 | Device ff_effects_max must be provided if FFBIT is set. |
| 62 | |
| 63 | Device abs_info fields are provided to set the device axes information. It is an array of below |
| 64 | objects: |
| 65 | | Field | Type | Description | |
| 66 | |:-------------:|:-------------:|:-------------------------- | |
| 67 | | code | integer | Axis code | |
| 68 | | info | object | ABS information object | |
| 69 | |
| 70 | ABS information object is defined as below: |
| 71 | | Field | Type | Description | |
| 72 | |:-------------:|:-------------:|:-------------------------- | |
| 73 | | value | integer | Latest reported value | |
| 74 | | minimum | integer | Minimum value for the axis | |
| 75 | | maximum | integer | Maximum value for the axis | |
| 76 | | fuzz | integer | fuzz value for noise filter| |
| 77 | | flat | integer | values to be discarded | |
| 78 | | resolution | integer | resolution of axis | |
| 79 | |
| 80 | See [struct input_absinfo][4]) definitions. |
| 81 | |
| 82 | Example: |
| 83 | ```json |
| 84 | |
| 85 | { |
| 86 | "id": 1, |
| 87 | "command": "register", |
| 88 | "name": "Keyboard (Test)", |
| 89 | "vid": 0x18d2, |
| 90 | "pid": 0x2c42, |
| 91 | "bus": "usb", |
| 92 | "configuration":[ |
| 93 | {"type":100, "data":[1, 21]}, // UI_SET_EVBIT : EV_KEY and EV_FF |
| 94 | {"type":101, "data":[11, 2, 3, 4]}, // UI_SET_KEYBIT : KEY_0 KEY_1 KEY_2 KEY_3 |
| 95 | {"type":107, "data":[80]} // UI_SET_FFBIT : FF_RUMBLE |
| 96 | ], |
| 97 | "ff_effects_max" : 1, |
| 98 | "abs_info": [ |
| 99 | {"code":1, "info": {"value":20, "minimum":-255, |
| 100 | "maximum":255, "fuzz":0, "flat":0, "resolution":1} |
| 101 | }, |
| 102 | {"code":8, "info": {"value":-50, "minimum":-255, |
| 103 | "maximum":255, "fuzz":0, "flat":0, "resolution":1} |
| 104 | } |
| 105 | ] |
| 106 | } |
| 107 | |
| 108 | ``` |
| 109 | 2. `delay` |
| 110 | Add a delay to command processing |
| 111 | |
| 112 | | Field | Type | Description | |
| 113 | |:-------------:|:-------------:|:-------------------------- | |
| 114 | | id | integer | Device id | |
| 115 | | command | string | Must be set to "delay" | |
| 116 | | duration | integer | Delay in milliseconds | |
| 117 | |
| 118 | Example: |
| 119 | ```json |
| 120 | { |
| 121 | "id": 1, |
| 122 | "command": "delay", |
| 123 | "duration": 10 |
| 124 | } |
| 125 | ``` |
| 126 | |
| 127 | 3. `inject` |
| 128 | Send an array of uinput event packets [type, code, value] to the uinput device |
| 129 | |
| 130 | | Field | Type | Description | |
| 131 | |:-------------:|:-------------:|:-------------------------- | |
| 132 | | id | integer | Device id | |
| 133 | | command | string | Must be set to "inject" | |
| 134 | | events | integer array | events to inject | |
| 135 | |
| 136 | The "events" parameter is an array of integers, encapsulates evdev input_event type, code and value, |
| 137 | see the example below. |
| 138 | |
| 139 | Example: |
| 140 | ```json |
| 141 | { |
| 142 | "id": 1, |
| 143 | "command": "inject", |
| 144 | "events": [0x01, 0xb, 0x1, // EV_KEY, KEY_0, DOWN |
| 145 | 0x00, 0x00, 0x00, // EV_SYN, SYN_REPORT, 0 |
| 146 | 0x01, 0x0b, 0x00, // EV_KEY, KEY_0, UP |
| 147 | 0x00, 0x00, 0x00, // EV_SYN, SYN_REPORT, 0 |
| 148 | 0x01, 0x2, 0x1, // EV_KEY, KEY_1, DOWN |
| 149 | 0x00, 0x00, 0x01, // EV_SYN, SYN_REPORT, 0 |
| 150 | 0x01, 0x02, 0x00, // EV_KEY, KEY_1, UP |
| 151 | 0x00, 0x00, 0x01 // EV_SYN, SYN_REPORT, 0 |
| 152 | ] |
| 153 | } |
| 154 | ``` |
| 155 | |
| 156 | ### Notes |
| 157 | 1. As soon as EOF is reached (either in interactive mode, or in file mode), |
| 158 | the device that was created will be unregistered. There is no |
| 159 | explicit command for unregistering a device. |
| 160 | 2. The `getevent` utility can used to print out the key events |
| 161 | for debugging purposes. |
| 162 | |
| 163 | [1]: https://developer.android.com/reference/android/hardware/input/InputManager.InputDeviceListener.html |
| 164 | [2]: ../../../../cts/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java |
| 165 | [3]: ../../../../cts/tests/tests/hardware/res/raw/ |
| 166 | [4]: ../../../../bionic/libc/kernel/uapi/linux/input.h |