简体   繁体   中英

Python evdev loop not reacting to keypresses

I am trying to work with the python evdev module (Python3 Interpreter / Linuxmint 20.1). I tried to run the example code of the documentation ( https://python-evdev.readthedocs.io/en/latest/tutorial.html#reading-events ):

>>> from evdev import InputDevice, categorize, ecodes
>>> dev = InputDevice('/dev/input/event1')

>>> print(dev)
device /dev/input/event1, name "Dell Dell USB Keyboard", phys "usb-0000:00:12.1-2/input0"

>>> for event in dev.read_loop():
...     if event.type == ecodes.EV_KEY:
...         print(categorize(event))
... # pressing 'a' and holding 'space'
key event at 1337016188.396030, 30 (KEY_A), down
key event at 1337016188.492033, 30 (KEY_A), up
key event at 1337016189.772129, 57 (KEY_SPACE), down
key event at 1337016190.275396, 57 (KEY_SPACE), hold
key event at 1337016190.284160, 57 (KEY_SPACE), up

But in my terminal no key events are printed out. There is also no error either. It just hangs in the loop and the letter of the key is printed to the console when I am pressing it. I checked with evtest in the VT before to make sure the code is refering to the correct event file - should be fine. The printed device is correct as well.

Does anyone know how to fix this or where the problem could be? (Could this be due to interferences with kernel processes? I checked with fuser and saw that same root processes are running on the eventfile)

Okay, solution was that more than one eventfile was related to the connected device. Got an other one now and everything works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM