Android getevent用法详解

getevent 指令用于获取 input 输入事件,比如获取按键上报信息、获取触摸屏上报信息等。

指令源码路径:/system/core/toolbox/getevent.c

getevent -h:查看 getevent 帮助信息

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -h
getevent -h
Usage: getevent [-t] [-n] [-s switchmask] [-S] [-v [mask]] [-d] [-p] [-i] [-l] [-q] [-c count] [-r] [device] -t: show time stamps -n: don't print newlines
    -s: print switch states for given bits -S: print all switch states -v: verbosity mask (errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64) -d: show HID descriptor, if available -p: show possible events (errs, dev, name, pos. events) -i: show all device info and possible events -l: label event types and names in plain text -q: quiet (clear verbosity mask) -c: print given number of events then exit -r: print rate events are received</pre>

getevent:显示当前有那些输入设备,数量与 /dev/input 目录下相同

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent
getevent
add device 1: /dev/input/event3
  name: "ILITEK Multi-Touch-V3020" add device 2: /dev/input/event2
  name: "PC Camera" add device 3: /dev/input/event1
  name: "gsensor" add device 4: /dev/input/event0
  name: "rk29-keypad" root@rk3288:/ # ls /dev/input
ls /dev/input
event0
event1
event2
event3</pre>

查看默认上报数据

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent /dev/input/event3
getevent /dev/input/event3 0003 0039 00000004
0003 0035 00002324
0003 0036 00001a9f 0001 014a 00000001
0003 0000 00002324
0003 0001 00001a9f 0000 0000 00000000
0003 0039 ffffffff 0001 014a 00000000
0000 0000 00000000</pre>

-t:显示时间戳

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">// 读取 event3 数据(触摸屏)
root@rk3288:/ # getevent -t /dev/input/event3
getevent -t /dev/input/event3
[ 1141.248434] 0003 0039 0000000e
[ 1141.248434] 0003 0035 00002cd4
[ 1141.248434] 0003 0036 00001a09
[ 1141.248434] 0001 014a 00000001 [ 1141.248434] 0003 0000 00002cd4
[ 1141.248434] 0003 0001 00001a09
[ 1141.248434] 0000 0000 00000000 [ 1141.322181] 0003 0039 ffffffff
[ 1141.322181] 0001 014a 00000000 [ 1141.322181] 0000 0000 00000000</pre>

-n:不换行打印

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -n /dev/input/event3
getevent -n /dev/input/event3 0003 0039 000000020003 0035 00002f000003 0036 00001a4e0001 014a 000000010003 0000 00002f000003 0001 00001a4e0000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000030003 0035 00002e880003 0036 000019b80001 014a 000000010003 0000 00002e880003 0001 000019b80000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000040003 0035 00002d700003 0036 00001a000001 014a 000000010003 0000 00002d700003 0001 00001a000000 0000 000000000003 0039 ffffffff0001 014a 000000000000 0000 000000000003 0039 000000050003 0035 00002d080003 0036 000019a50001 014a 000000010003 0000 00002d080003 0001 000019a50000 0000 000000000003 0039 ffffffff0001 014a 000000000000</pre>

-s:显示指定位的开关状态

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -s5 /dev/input/event3
getevent -s5 /dev/input/event3 0000</pre>

-S:显示所有位的开关状态

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -S /dev/input/event3
getevent -S /dev/input/event3 0000 </pre>

-v:根据 mask 值显示相关信息,执行后会一直显示上报数据

errs=1, dev=2, name=4, info=8, vers=16, pos. events=32, props=64

默认显示 dev| name| info| vers = 30;

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -v /dev/input/event3
getevent -v /dev/input/event3
add device 1: /dev/input/event3
  bus: 0003 vendor    222a
  product   004d
  version 0110 name: "ILITEK Multi-Touch-V3020" location: "usb-ff540000.usb-1.3/input0" id: "" version: 1.0.1 root@rk3288:/ # getevent -v30 /dev/input/event3
getevent -v30 /dev/input/event3
add device 1: /dev/input/event3
  bus: 0003 vendor    222a
  product   004d
  version 0110 name: "ILITEK Multi-Touch-V3020" location: "usb-ff540000.usb-1.3/input0" id: "" version: 1.0.1 root@rk3288:/ # getevent -v2 /dev/input/event3
getevent -v2 /dev/input/event3
add device 1: /dev/input/event3

root@rk3288:/ # getevent -v8 /dev/input/event3
getevent -v8 /dev/input/event3
  bus: 0003 vendor    222a
  product   004d
  version 0110 location: "usb-ff540000.usb-1.3/input0" id: "" root@rk3288:/ # getevent -v16 /dev/input/event3
getevent -v16 /dev/input/event3
  version: 1.0.1 root@rk3288:/ # getevent -v32 /dev/input/event3
getevent -v32 /dev/input/event3
  events:
    KEY (0001): 014a
    ABS (0003): 0000  : value 12008, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0001  : value 5790, min 0, max 9600, fuzz 0, flat 0, resolution 32 002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0036  : value 0, min 0, max 9600, fuzz 0, flat 0, resolution 32
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0</pre>

-d:如果设备可用,显示设备隐藏的描述信息

-p:显示设备支持的事件类型和编码方式

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -p /dev/input/event3
getevent -p /dev/input/event3
add device 1: /dev/input/event3
  name: "ILITEK Multi-Touch-V3020" events:
    KEY (0001): 014a
    ABS (0003): 0000  : value 13084, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0001  : value 5284, min 0, max 9600, fuzz 0, flat 0, resolution 32 002f  : value 0, min 0, max 9, fuzz 0, flat 0, resolution 0
                0035  : value 0, min 0, max 16384, fuzz 0, flat 0, resolution 31
                0036  : value 0, min 0, max 9600, fuzz 0, flat 0, resolution 32
                0039  : value 0, min 0, max 65535, fuzz 0, flat 0, resolution 0 input props:
    INPUT_PROP_DIRECT</pre>

-i:显示设备的所有信息和支持的事件,比 -p 显示更多信息

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -i /dev/input/event3</pre>

-l:以文本形式输出事件类型和名称,比 -t 更清楚直观

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">// 读取 event3 数据(触摸屏)
root@rk3288:/ # getevent -l /dev/input/event3
getevent -l /dev/input/event3 // 事件类型      事件码              事件值
EV_ABS       ABS_MT_TRACKING_ID   0000000f
EV_ABS       ABS_MT_POSITION_X    00002bbc
EV_ABS       ABS_MT_POSITION_Y    00001b6d
EV_KEY       BTN_TOUCH            DOWN
EV_ABS       ABS_X                00002bbc
EV_ABS       ABS_Y                00001b6d
EV_SYN       SYN_REPORT 00000000 EV_ABS       ABS_MT_TRACKING_ID   ffffffff
EV_KEY       BTN_TOUCH            UP
EV_SYN       SYN_REPORT 00000000</pre>

-q:暂时不会使用

-c:打印固定数量的事件并退出

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -c 10 /dev/input/event3
getevent -c 10 /dev/input/event3 0003 0039 00000012
0003 0035 000038a4 0003 0036 000008f5 0001 014a 00000001
0003 0000 000038a4 0003 0001 000008f5 0000 0000 00000000
0003 0039 ffffffff 0001 014a 00000000
0000 0000 00000000</pre>

-r:显示事件上报速率

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">// 检测触摸屏报点速率
root@rk3288:/ # getevent -r /dev/input/event3
getevent -r /dev/input/event3 0003 0039 00000015
0003 0035 000030d8 0003 0036 00001954
0001 014a 00000001
0003 0000 000030d8 0003 0001 00001954
0000 0000 00000000 rate 0
0003 0039 ffffffff 0001 014a 00000000
0000 0000 00000000 rate 9</pre>

参数可以组合使用,一次性查看需要的触摸屏信息

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px !important; background: rgb(238, 238, 238); border: 0px; overflow: auto; border-radius: 2px;">root@rk3288:/ # getevent -tlr /dev/input/event3
getevent -tlr /dev/input/event3
[ 2514.550104] EV_ABS       ABS_MT_TRACKING_ID   0000001c
[ 2514.550104] EV_ABS       ABS_MT_POSITION_X    00002dac
[ 2514.550104] EV_ABS       ABS_MT_POSITION_Y    000018ca
[ 2514.550104] EV_KEY       BTN_TOUCH            DOWN
[ 2514.550104] EV_ABS       ABS_X                00002dac
[ 2514.550104] EV_ABS       ABS_Y                000018ca
[ 2514.550104] EV_SYN       SYN_REPORT           00000000             rate 0 [ 2514.638845] EV_ABS       ABS_MT_TRACKING_ID   ffffffff
[ 2514.638845] EV_KEY       BTN_TOUCH            UP
[ 2514.638845] EV_SYN       SYN_REPORT           00000000             rate 11</pre>

转自 Android getevent用法详解

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,589评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,615评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,933评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,976评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,999评论 6 393
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,775评论 1 307
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,474评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,359评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,854评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,007评论 3 338
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,146评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,826评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,484评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,029评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,153评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,420评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,107评论 2 356