1

我使用 python-evdev 库来检测键盘事件。

但是我有一个问题,我需要在检测到键后刷新键盘事件。

例子:

from evdev import InputDevice, categorize, ecodes

dev = InputDevice('/dev/input/event1')
for event in dev.read_loop():
    if event.type == ecodes.EV_KEY:
         print(categorize(event))
         #to do..............
         >>>flush here> KEYBOARD EVENT>>

如何刷新开发?

4

1 回答 1

1

处理完事件后,使用device.read_one()读取队列中的所有事件(如果队列为空,read_one()将返回None )。

for event in device.read_loop():
    do_stuff_with_your_event(event)
    while device.read_one() != None:
        pass
于 2016-03-21T00:23:37.823 回答