python InputDevice fflush

1k views Asked by At

I use python-evdev library for detect keyboard event.

But I have a problem, I need flush the keyboard event after I have detect key.

example:

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>>

how fflush dev ?

1

There are 1 answers

1
Vincenzo Bono On

After doing your stuff with your event, use device.read_one() to read all the ones in the queue (read_one() returns None if the queue is empty).

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