Search code examples
pythonpyqtpygtkxlibxorg

How get input device path with Xlib in Xorg?


There is some way to get the device path of a mouse and keyboard using Xlib based in a looping with XNextEvent? I need to know what /dev/input/event* generates a event specific like mouse press and keyboard key F1 press.

I'm using evdev for input devices in Xorg, I searched documentation and cannot find a way.

I accept too suggestion of some app that I can use to identify input device based in events like mouse press and keyboard press.

Thanks.

Edit: If there is a way to make this using another lib, preferable one with bindings for python, please let me know.


Solution

  • I realize that Xlib do not have a method to get the file descriptor of the input devices, so I figured out another way to resolve this case, is not ready yet, but apparently is the best way to follow, just posting here for someone with the same problem.

    I'm using the module python-evdev (installed with pip in ubuntu), with this module I can monitor the devices is /dev/input/event*, so I just need to start a thread for each device that I previous identified which is a mouse or keyboard (using the module evdev and checking if device have "capabilities(verbose=True)" with event codes like ecodes.KEY_F1 and ecodes.BTN_MOUSE), and when a event occur, write to a shared variable, that I should monitor.

    For the graphic interface running in Xorg, without Windows Managers, I using python-glade2, works like a charm, I run a Xorg with python-glade2 app using xinit.