0

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Swi Jason
  • 471
  • 1
  • 3
  • 10

1 Answers1

2

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.

kabanus
  • 24,623
  • 6
  • 41
  • 74
  • Just reading this https://www.reddit.com/r/linuxquestions/comments/bh4ex1/is_adding_a_user_to_input_group_secure/ , and I am wondering if indeed adding a user to input is not such a great idea? – nico Jul 07 '21 at 08:06
  • On the other hand... https://askubuntu.com/questions/1057120/is-adding-a-user-to-input-group-secure – nico Jul 07 '21 at 08:12