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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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
回答2:
Using evtest is very helpful. It can list all your input devices by name, and allows you to monitor each device's events.
回答3:
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.
回答4:
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