3

I need to get list of input devices on Linux operating system. Something similar to parsing /proc/bus/input/devices, but I actually don't want to reinvent the wheel. I believe there should be some system functions to enumerate devices and things like that. It is an embedded Linux, so I am limited in libraries I can use.

axe
  • 2,331
  • 4
  • 31
  • 53
  • 1
    What do you actually want to do? In general, "parsing /proc/bus/input/devices" is indeed what you'd want to do to get a list of input devices. The format itself is generally pretty easy to parse... – Mats Petersson Oct 14 '13 at 16:16
  • I want to move the mouse. XWarpPointer is not working, because I don't have -lX11 with arm-linux-gnueabi-gcc. I'm writing events directly to the /dev/input/event3 and it works, but I need to know exactly which input file should I write events to. So I need to find mouse input device or move the mouse any other way. – axe Oct 14 '13 at 16:20
  • You could consider configuring `udev` to easy your process. And parsing `/proc/` files is indeed the prefered way to interact with the kernel on many topics. – Basile Starynkevitch Oct 14 '13 at 16:24

2 Answers2

2

It sounds like you wanted the command:

libinput list-devices
acran
  • 7,070
  • 1
  • 18
  • 35
solanum
  • 21
  • 3
  • hi @solanum, unfortunately, this command didn't work on my device (5.10.0-7-amd64 #1 SMP Debian 5.10.40-1 (2021-05-28) x86_64 GNU/Linux). I tried `$ whereis libinput` which results `libinput: /usr/share/libinput /usr/share/man/man4/libinput.4.gz`, which appears to be a directory. could you help me out here? – Meraj al Maksud Jun 28 '21 at 09:33
  • Use `sudo apt install libinput-tools` to get the `libinput` command. – Mahmoud Al-Qudsi May 19 '23 at 17:24
0

So, to find the mouse event handler, you search for a line that begins with "H:" and has a "mouseN" on it. It will then have a "eventM" on the same line. Should be doable with about half a dozen or so lines of code to open /proc/bus/input/devices, read a line, check if it's "H:" start, and if so, parse the rest of it for "mouse" and "event" bits.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
  • 1
    I found 9 lines with `mouseN` entry in the H: section, for example look at those two `H: Handlers=mouse0 event3 H: Handlers=mouse1 event4` It works when I write events to /dev/input/event3, but doesn't work for /dev/input/event4. So how should I understand which device is the right one? – axe Oct 14 '13 at 16:34
  • 1
    Strange. Do you have multiple "pointing" type devices attached to your system? I only have one such line... – Mats Petersson Oct 14 '13 at 16:36
  • 1
    Here is another output from my VM running ubuntu. `H: Handlers=kbd event0 H: Handlers=kbd event1 H: Handlers=sysrq kbd event2 H: Handlers=mouse0 event3 js0 H: Handlers=mouse1 event4 H: Handlers=event5` – axe Oct 14 '13 at 16:37
  • 1
    Yes, but I still don't understand why writing to one works while writing to the other doesn't – axe Oct 14 '13 at 16:39
  • 1
    Presumably because only one is actually connected to whatever your "mouse cursor" is actually appearing on (your GUI). I'm afraid I don't know how you determine which is actually being used - it is most likely some sort of configuration/detection code in the GUI code itself that deals with that. – Mats Petersson Oct 14 '13 at 16:43
  • 1
    Not really. `Handlers=mouse1 event4` is the `Logitech USB Optical Mouse` which actually works, but writing to /dev/input/event4 does nothing. Do I understand it right? `event4` in `H:` line means that input device is `/dev/input/event4`? – axe Oct 14 '13 at 16:45
  • 1
    How bizarre. Yes, event4 will correspond to /dev/input/event4. – Mats Petersson Oct 14 '13 at 16:49