How can I know which of the /dev/input/eventX (X=0

2019-03-07 23:10发布

I am trying to capture linux keyboard/mouse input, and I am reading events from like /dev/input/event2. But it seems the input are sometimes directed to /dev/input/event2, sometimes to /dev/input/event3. I wonder if there is a place I can find out which of the stream has the input?

4条回答
你好瞎i
2楼-- · 2019-03-07 23:51

To find out, go to /dev/input/by-id or /dev/input/by-path and do a ls -l to find out which symlink points to which event<*>.

Also, I thought it would be helpful for all those who come across this page to find this helpful link to some code which captures keyboard events.

查看更多
再贱就再见
3楼-- · 2019-03-08 00:02

Using evtest is very helpful. It can list all your input devices by name, and allows you to monitor each device's events.

查看更多
太酷不给撩
4楼-- · 2019-03-08 00:07

Run this in Terminal, it will work just fine:

cat /proc/bus/input/devices | awk '/keyboard/{for(a=0;a>=0;a++){getline;{if(/kbd/==1){ print 
$NF;exit 0;}}}}'

Source

查看更多
淡お忘
5楼-- · 2019-03-08 00:08

Just stumbled across this -- rather late in the day.

You can find out the names and other attributes of different devices using:

cat /proc/bus/input/devices
查看更多
登录 后发表回答