I'm writing a game using python, and I need to monitor keyboard events using evdev. I'm new to this lib, so I followed the tutorial online. The following is the script mentioned in the tutorial:
>>> import evdev
>>> devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
>>> for device in devices:
>>> print(device.path, device.name, device.phys)
However, after running the code, the output of list_devices() is None, which indicates that there is no input devices on my computer(a Dell laptop).Why?
Checked it on my debian
Buster system, I think it should be the same for you - you need special access to read and write to the devices. For example, sudo
should work, try:
bash>sudo python3
>>>import evdev; evdev.list_devices()
Found the relavent doc:
If you do not see any devices, ensure that your user is in the correct group (typically input) to have read/write access.
So add your user to the input
group - probably safer than sudo
.