Is there a way to read from /dev/input
devices, without needing root privileges?
In my case, I would like to use the Python library evdev to read from multiple keyboards (so that I know which keyboard the signal comes from), so simply using stdin
is not possible.
Always having to call the program with sudo-privileges would not be too elegant – is it, for example, possible to chmod the /dev/input
directory (security does not matter in my case)?
Or, even better, is there another way of directly reading from input devices?
Best Answer
This stack overflow article seems to answer your question.
See the second answer. The accepted answer is:
Check to see to which group the device files belong to. For example, here I get:
The user executing your program needs to be in the plugdev group on this system. Something similar is probably the case on your system.
If you're asking for a way to circumvent that (reading or writing to the device without being in the group), then no. That would obviously defeat the purpose of security though user groups.
An alternative to reading the event devices directly would be to use an appropriate user space API instead. For example, to read the keyboard you would use ncurses, and to read the mouse you would use GPM.