目录
前言
在日常调试中,可能会遇到键盘、鼠标、触摸屏等输入设备无响应等异常情况,一般可以通过更换设备判断异常。但在遇到更换正常设备后输入仍然异常的情况下,可以借助evtest工具进行查看内核的上报事件信息,协助定位问题所在。
evtest
事件响应工具evtest可用于调试和诊断输入设备相关问题。
evtest的工作原理
evtest通过访问/dev/input/eventX设备文件,实时捕获输入设备上报的原始事件数据。它基于Linux输入子系统(Input Subsystem)的evdev接口,
将二进制事件流转换为人类可读格式,包含时间戳、事件类型、事件代码和数值等关键信息。该工具支持键盘、鼠标、触摸屏等多种输入设备,并能区分EV_KEY(按键)、EV_ABS(绝对坐标)等事件类型。
evtest的命令
帮助命令
# /mnt/card/evtest -h
/mnt/card/evtest: invalid option -- h
USAGE:
Capture mode:
evtest [--grab] /dev/input/eventX
--grab grab the device for exclusive access
Query mode: (check exit code)
evtest --query /dev/input/eventX <type> <value>
<type> is one of: EV_KEY, EV_SW, EV_LED, EV_SND
<value> can either be a numerical value, or the textual name of the
key/switch/LED/sound being queried (e.g. SW_DOCK).
列出所有输入设备和设备编号命令
# evtest
evtest: No such file or directory
# /mnt/card/evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: test-pmc
/dev/input/event1: matrix-keypad
/dev/input/event2: goodix-ts
/dev/input/event3: test-ir
/dev/input/event4: test-gsensor
Select the device event number [0-4]: 1
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "matrix-keypad"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 8 (KEY_7)
Event code 9 (KEY_8)
Event code 16 (KEY_Q)
Event code 17 (KEY_W)
Event code 18 (KEY_E)
Event code 19 (KEY_R)
Event code 20 (KEY_T)
Event code 21 (KEY_Y)
Event code 22 (KEY_U)
Event code 28 (KEY_ENTER)
Event code 39 (KEY_SEMICOLON)
Event code 58 (KEY_CAPSLOCK)
Event code 103 (KEY_UP)
Event code 108 (KEY_DOWN)
Event code 116 (KEY_POWER)
Event code 139 (KEY_MENU)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
捕获模式命令
如果在捕获模式下给出--grab标志,evtest会在设备上保持一个EVIOCGRAB模式,其中EVIOCGRAB是Linux系统中
用于控制输入设备独占权限的ioctrl命令,主要用于设置或取消设备的事件抓取独占模式,通过调用EVIOCGRAB,进程可以
独占特定输入设备(如触摸屏、键盘)的事件处理,其它进程将无法接收该设备的事件。
# /mnt/card/evtest --grab /dev/input/event1
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0
Input device name: "matrix-keypad"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 8 (KEY_7)
Event code 9 (KEY_8)
Event code 16 (KEY_Q)
Event code 17 (KEY_W)
Event code 18 (KEY_E)
Event code 19 (KEY_R)
Event code 20 (KEY_T)
Event code 21 (KEY_Y)
Event code 22 (KEY_U)
Event code 28 (KEY_ENTER)
Event code 39 (KEY_SEMICOLON)
Event code 58 (KEY_CAPSLOCK)
Event code 103 (KEY_UP)
Event code 108 (KEY_DOWN)
Event code 116 (KEY_POWER)
Event code 139 (KEY_MENU)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
Event: time 1686708523.398920, type 4 (EV_MSC), code 4 (MSC_SCAN), value 00
Event: time 1686708523.398920, type 1 (EV_KEY), code 116 (KEY_POWER), value 1
Event: time 1686708523.398920, -------------- SYN_REPORT ------------
Event: time 1686708523.478956, type 4 (EV_MSC), code 4 (MSC_SCAN), value 00
Event: time 1686708523.478956, type 1 (EV_KEY), code 116 (KEY_POWER), value 0
Event: time 1686708523.478956, -------------- SYN_REPORT ------------
Event: time 1686708524.448926, type 4 (EV_MSC), code 4 (MSC_SCAN), value 00
Event: time 1686708524.448926, type 1 (EV_KEY), code 116 (KEY_POWER), value 1
查询模式命令
使用查询模式时,evtest执行一次性查询事件类型和特定键值的状态。
其中事件类型是以下之一:EV_KEY、EV_SW、EV_LED、EV_SND,值可以是十进制表示(例如44)或
十六进制表示(例如0x2C),或者是按键、开关、声音、LED的常数名称(例如KEY_Z)。
# evtest --query /dev/input/pwr_key EV_KEY KEY_POWER
总结
evtest工具是打印evdev内核事件的工具,它直接从内核设备中读取并打印设备描述的带有值和符号名的事件,可以用来调试鼠标、键盘、触摸屏等输入设备,方便定位问题及提供判断依据。
4950

被折叠的 条评论
为什么被折叠?



