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

时间:2019-02-20 22:54:31

标签: python evdev

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

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_L是否这样做。

0 个答案:

没有答案