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?
我正在尝试捕获linux键盘/鼠标输入,并且正在读取/dev/input/event2之类的事件。但似乎输入有时指向/dev/input/event2,有时指向/dev/input/event3。我想知道是否有一个地方可以让我知道哪个流有输入?
4 个解决方案
#1
54
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
12
Using evtest is very helpful. It can list all your input devices by name, and allows you to monitor each device's events.
使用evtest非常有用。它可以按名称列出所有输入设备,并允许您监视每个设备的事件。
#3
10
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<*>
.
要找到答案,请转到/dev/input/by id或/dev/input/by-path并执行ls -l,以找出哪个符号链接指向哪个事件<*>。
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
3
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;}}}}'
源
#1
54
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
12
Using evtest is very helpful. It can list all your input devices by name, and allows you to monitor each device's events.
使用evtest非常有用。它可以按名称列出所有输入设备,并允许您监视每个设备的事件。
#3
10
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<*>
.
要找到答案,请转到/dev/input/by id或/dev/input/by-path并执行ls -l,以找出哪个符号链接指向哪个事件<*>。
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
3
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;}}}}'
源