我怎么知道哪个 /dev/input/eventX (X=0..7) 有 Linux 输入流?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6990978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I know which of the /dev/input/eventX (X=0..7) have the Linux input stream?
提问by Justin Zhang
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 键盘/鼠标输入,并且正在从 like 读取事件/dev/input/event2
。但似乎输入有时指向/dev/input/event2
,有时指向/dev/input/event3
。我想知道是否有一个地方可以找出哪个流有输入?
回答by Devesh
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
并执行 a
ls -l
以找出哪个符号链接指向哪个event<*>
.
Also, I thought it would be helpful for all those who come across this page to find this helpful linkto some code which captures keyboard events.
回答by dajames
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
回答by madhat1
Using sudo evtest
is very helpful.
It will list all your input devices by name and corresponding event number. Then you can enter device event number of your interest and monitor its events.
使用sudo evtest
非常有帮助。它将按名称和相应的事件编号列出所有输入设备。然后您可以输入您感兴趣的设备事件编号并监控其事件。
回答by Cyber-Surfer
回答by mazKnez
I know it's a little late to reply but I hope this is helpful for friends.
我知道现在回复有点晚了,但我希望这对朋友有所帮助。
“mice” contains mouse input data, but to find the file related to the keyboards we need to check the files in folder “by-path”, keyboards file names end with “event-kbd”. We need to find the links to the keyboards, and then we can find the keyboards event file. The following commands can do this automatically for us:
“mice”包含鼠标输入数据,但要找到与键盘相关的文件,我们需要检查文件夹“by-path”中的文件,键盘文件名以“ event-kbd”结尾。我们需要找到指向键盘的链接,然后我们才能找到键盘事件文件。以下命令可以为我们自动执行此操作:
kbdEvents=($(ls /dev/input/by-path | grep "event-kbd"))
for forCounter in "${kbdEvents[@]}"
do
eventFile=$(readlink --canonicalize "/dev/input/by-path/${forCounter}")
# do anything ...
done
This code is part of the code for the break time on my personal website : mazKnez.com
此代码是我个人网站上的休息时间代码的一部分:mazKnez.com