问题
I have a program that is listening to a certain event file handle. Is there a file I can read to get details about the specific event's device that I am listening to?
回答1:
Assuming that (a) you're on Linux and (b) you have sysfs
mounted (typically on /sys
), you can look at /sys/class/input/eventX
. This will be a symlink into the device tree; this should provide you some device details. For example:
$ readlink /sys/class/input/event4
../../devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.4/2-1.4:1.1/input/input4/event4
For USB devices, you could then probably mount a usbfs
filesystem and check out the devices
file for more information.
回答2:
Do you have access to the file descriptor or is this an external program? If this is your fd to the actual device, a list of ioctls provides you with most info you'll need. Have a look at print_device_info from evtest, it does exactly that:
http://cgit.freedesktop.org/evtest/tree/evtest.c#n753
来源:https://stackoverflow.com/questions/10341349/finding-the-description-of-the-device-connected-to-dev-input-eventx