将evdev输入转换为可理解的信息

2024-04-27 11:11:33 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,我已经成功地使用以下代码跟踪鼠标和键盘事件

devices = map(InputDevice, ('/dev/input/event1', '/dev/input/event0'))
devices = {dev.fd: dev for dev in devices}

for dev in devices.values(): print(dev)

while True:
    r, w, x = select(devices, [], [])
    for fd in r:
            for event in devices[fd].read():
                    print(event)

当我按下一个键或移动鼠标时,我从这个代码中得到的数据如下:

event at 1550702472.373994, code 00, type 00, val 00
event at 1550702472.389984, code 00, type 02, val -5
event at 1550702472.389984, code 01, type 02, val -2
event at 1550702472.389984, code 00, type 00, val 00
event at 1550702472.405988, code 00, type 02, val -3
event at 1550702472.405988, code 00, type 00, val 00
event at 1550702472.421987, code 00, type 02, val -2

我的问题是如何转换这些数据或分析这些数字以获得像实际键一样的良好输出。类似于分析1550702472.xxx数字以获得某个键或者下面的数字。你知道吗

更新:当我说print(categorize(event))时,我得到:

key event at 1550703468.964836, 38 (KEY_L), down
synchronization event at 1550703468.964836, SYN_REPORT
event at 1550703469.052829, code 04, type 04, val 458767
key event at 1550703469.052829, 38 (KEY_L), up
synchronization event at 1550703469.052829, SYN_REPORT
relative axis event at 1550703472.093778, REL_Y
synchronization event at 1550703472.093778, SYN_REPORT
relative axis event at 1550703472.125780, REL_X
synchronization event at 1550703472.125780, SYN_REPORT
relative axis event at 1550703472.141764, REL_X

还是同样的问题,如果KEY\u L这样做,我能用什么数组来表示呢。你知道吗


Tags: indevreporteventfortypecode数字