Finding the description of the device connected to /dev/input/eventX

老子叫甜甜 提交于 2019-12-24 07:07:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!