我是靠谱客的博主 发嗲便当,最近开发中收集的这篇文章主要介绍Android getevent用法详解,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

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

getevent -h:查看 getevent 帮助信息

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

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

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

查看默认上报数据

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

-t:显示时间戳

// 读取 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

-n:不换行打印

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

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

root@rk3288:/ # getevent -s5 /dev/input/event3
getevent -s5 /dev/input/event3
0000

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

root@rk3288:/ # getevent -S /dev/input/event3
getevent -S /dev/input/event3
0000 

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

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

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

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

 

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

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

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

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

root@rk3288:/ # getevent -i /dev/input/event3

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

// 读取 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

-q:暂时不会使用

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

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

-r:显示事件上报速率

// 检测触摸屏报点速率
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

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

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

 

最后

以上就是发嗲便当为你收集整理的Android getevent用法详解的全部内容,希望文章能够帮你解决Android getevent用法详解所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部