adb shell:getevent and sendevent

getevent

The getevent tool runs on the device and provides information about input devices and a live dump of kernel input events.

This tool is useful for ensuring device drivers are reporting the expected set of capabilities for each input device and are generating the desired stream of input events.

Showing device capabilities

Use the -p option with the adb command to see all of the keys and axes a device reports.

adb shell su -- getevent -p

The following example lists the Linux key codes and other events a particular keyboard says it supports.

could not get driver version for /dev/input/mouse0, Not a typewriter
could not get driver version for /dev/input/mice, Not a typewriter
add device 1: /dev/input/event7
  name:     "msm8953-snd-card-mtp Button Jack"
  events:
    KEY (0001): 0072  0073  00e2
  input props:
    INPUT_PROP_ACCELEROMETER
add device 2: /dev/input/event6
  name:     "msm8953-snd-card-mtp Headset Jack"
  events:
    SW  (0005): 0002  0004  0006  0007  000e  000f  0010  0011
  input props:
    <none>
add device 3: /dev/input/event5
  name:     "goodixfp"
  events:
    KEY (0001): 0043  0066  0067  0069  006a  006c  0074  008b
                009e  00ac  00bd  00d4  00fd  00fe  0252
  input props:
    <none>
add device 4: /dev/input/event2
  name:     "hbtp_vm"
  events:
    KEY (0001): 0110  0111
    REL (0002): 0000  0001
  input props:
    INPUT_PROP_DIRECT
add device 5: /dev/input/event0
  name:     "qpnp_pon"
  events:
    KEY (0001): 0072  0074
  input props:
    INPUT_PROP_ACCELEROMETER
add device 6: /dev/input/event4
  name:     "vivo_virtual_key"
  events:
    KEY (0001): 008b  009e  00ac
  input props:
    <none>
add device 7: /dev/input/event3
  name:     "gpio-keys"
  events:
    KEY (0001): 0066  0073
  input props:
    <none>
add device 8: /dev/input/event1
  name:     "synaptics_dsx_i2c"
  events:
    KEY (0001): 0011  0012  0018  001e  0021  002e  0032  0067
                0069  006a  008b  008f  009e  00ac  00f9  00fa
                00fc  0145  014a
    ABS (0003): 002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0030  : value 0, min 0, max 31, fuzz 0, flat 0, resolution 0
                0031  : value 0, min 0, max 31, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 1080, fuzz 0, flat 0, resolution 0
                0036  : value 0, min 0, max 1920, fuzz 0, flat 0, resolution 0
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
  input props:
    INPUT_PROP_DIRECT

Use the -i option to get more information, including HID mapping tables and debugging information.

Use the -l option to display textual labels for all event codes.

adb shell su -- getevent -lp /dev/input/event1 

Example:

add device 1: /dev/input/event1
  name:     "synaptics_dsx_i2c"
  events:
    KEY (0001): KEY_W                 KEY_E                 KEY_O                 KEY_A
                KEY_F                 KEY_C                 KEY_M                 KEY_UP
                KEY_LEFT              KEY_RIGHT             KEY_MENU              KEY_WAKEUP
                KEY_BACK              KEY_HOMEPAGE          00f9                  00fa
                00fc                  BTN_TOOL_FINGER       BTN_TOUCH
    ABS (0003): ABS_MT_SLOT           : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                ABS_MT_TOUCH_MAJOR    : value 0, min 0, max 31, fuzz 0, flat 0, resolution 0
                ABS_MT_TOUCH_MINOR    : value 0, min 0, max 31, fuzz 0, flat 0, resolution 0
                ABS_MT_POSITION_X     : value 0, min 0, max 1080, fuzz 0, flat 0, resolution 0
                ABS_MT_POSITION_Y     : value 0, min 0, max 1920, fuzz 0, flat 0, resolution 0
                ABS_MT_TRACKING_ID    : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0
  input props:
    INPUT_PROP_DIRECT

Showing live events

The following example shows a two-finger multi-touch gesture for a touchscreen using the Linux multi-touch input protocol "B". The -l option displays textual labels and the -t option displays timestamps.

adb shell su -- getevent -lt /dev/input/event1 

Example:

[   23064.140535] EV_ABS       ABS_MT_TRACKING_ID   000001c1
[   23064.140535] EV_KEY       BTN_TOUCH            DOWN
[   23064.140535] EV_KEY       BTN_TOOL_FINGER      DOWN
[   23064.140535] EV_ABS       ABS_MT_POSITION_X    00000253
[   23064.140535] EV_ABS       ABS_MT_POSITION_Y    0000072d
[   23064.140535] EV_ABS       ABS_MT_TOUCH_MAJOR   00000007
[   23064.140535] EV_SYN       SYN_REPORT           00000000
[   23064.153731] EV_ABS       ABS_MT_POSITION_X    00000252
[   23064.153731] EV_ABS       ABS_MT_POSITION_Y    00000728
[   23064.153731] EV_ABS       ABS_MT_TOUCH_MINOR   00000007
[   23064.153731] EV_SYN       SYN_REPORT           00000000
[   23064.256918] EV_SYN       SYN_REPORT           00000000
[   23064.269169] EV_ABS       ABS_MT_POSITION_X    00000226
[   23064.269169] EV_ABS       ABS_MT_POSITION_Y    0000054f
[   23064.269169] EV_ABS       ABS_MT_TOUCH_MINOR   00000006
[   23064.269169] EV_SYN       SYN_REPORT           00000000
[   23064.281610] EV_ABS       ABS_MT_TRACKING_ID   ffffffff
[   23064.281610] EV_KEY       BTN_TOUCH            UP
[   23064.281610] EV_KEY       BTN_TOOL_FINGER      UP
[   23064.281610] EV_SYN       SYN_REPORT           00000000
[   23065.740386] EV_ABS       ABS_MT_TRACKING_ID   000001c2
[   23065.740386] EV_KEY       BTN_TOUCH            DOWN
[   23065.740386] EV_KEY       BTN_TOOL_FINGER      DOWN

sendevent

use: sendevent device type code value

Example

below shell code shows how to click the power button

adb shell sendevent /dev/input/event0 1 116 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 116 0
adb shell sendevent /dev/input/event0 0 0 0

Recommend articles