Detailed explanation of Android getevent usage example
Recently, I have been testing common commands for device key presses. I feel that these commands are all, but I just don’t know how to find them.
After reading several blog posts, I found that there was a getevent, which refers to such a command.
The first thing to be noted is that the getevent command can be followed by the specific input device, such as getevent /dev/iput/event0, which can filter out some input devices that do not need to be displayed.
I still couldn't find any ideas in my previous use, and I also used them step by step.
First look at the -p option. The -p option is used to output some information related to the input device, such as getevent -p /dev/input/event0:
add device 1 : /dev/input/event0: name: “radio_key” events: KEY (0001): 0043 0044 0057 0058 input props:
Then the -i option is similar to the -p option, but the information displayed is richer. getevent -i /dev/input/event0:
add device 1: /dev/input/event0 bus: 0000 vendor 0000 product 0000 version 0000 name: “radio_key” location: “” id: “” version: 1.0.1 events: KEY (0001): 0043 0044 0057 0058 input props:
For the -p or -i options, it can help us determine whether the input device has been successfully registered.
Let’s look at the -l option. First, let’s take a look without adding the -l option. Enter the getevent /dev/input/event7 command. Note that event7 is the input device of the touch screen:
0001 014a 00000001 0003 0030 000000ff 0003 0035 00000262 0003 0036 00000546 0003 0039 00000011 0000 0002 00000000 0000 0000 00000000 0001 014a 00000000 0000 0002 00000000 0000 0000 00000000
Have you seen it? What I got is a set of information. If you only look at the numbers, you don’t know the specific meaning. So what if you add the -l option, getevent -l /dev/input/event7:
EV_KEY BTN_TOUCH DOWN EV_ABS ABS_MT_TOUCH_MAJOR 000000ff EV_ABS ABS_MT_POSITION_X 00000262 EV_ABS ABS_MT_POSITION_Y 00000546 EV_ABS ABS_MT_TRACKING_ID 00000011 EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000 EV_KEY BTN_TOUCH UP EV_SYN SYN_MT_REPORT 00000000 EV_SYN SYN_REPORT 00000000
We can see that it is easier to understand this way. The formats are event type, event code, and event value. As for the meanings they represent, you can refer to the input device-related things.
Let’s look at the -r option. The -r option can output the input report rate, such as getevent -r /dev/input/event7:
0000 0000 00000000 rate 83 0003 0030 0000004d 0003 0035 0000024e 0003 0036 00000364 0003 0039 00000000 0000 0002 00000000 0000 0000 00000000 rate 83 0003 0030 0000004c 0003 0035 0000024f 0003 0036 00000364 0003 0039 00000000 0000 0002 00000000 0000 0000 00000000 rate 83
Use this option to help us detect whether the input report rate meets our requirements, such as detecting the TP point rate.
For the getevent command options, we will introduce these. For other usages, you can refer to the getevent command usage above. In addition, these command options can be used in combination, such as getevent -lr /dev/input/event7.
I discovered these commands when I was detecting the device keys and felt that the physical key commands could not be found.
The sendevent command corresponds to getevent, but the input of the sendevent command is a bit complicated, and you can use another command input instead. For example, entering input keyevent KEYCODE_POWER means pressing the power key again.
Thank you for reading, I hope it can help you. Thank you for your support for this site!