python InputDevice fflush

时间:2015-06-20 13:53:29

标签: python keyboard flush fflush evdev

我使用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>>

如何fflush dev?

1 个答案:

答案 0 :(得分:1)

完成事件后,使用 device.read_one()读取队列中的所有内容( read_one()返回如果队列是空的。)

for event in device.read_loop():
    do_stuff_with_your_event(event)
    while device.read_one() != None:
        pass