Reputation: 701
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?
Upvotes: 70
Views: 91608
Reputation: 71
At least NTFS-3G forbids such names because they can be problematic:
And judging from your fuseblk mount points, you're using ntfs-3g to mount those partitions. I haven't looked into the code enough to determine if there's a way to switch this checking off.
Upvotes: 0
Reputation: 725
Following the others hints and some trial and error as I ain't a bash wizard, this is how I am using to get the inputXX of my bluetooth controller, to use with xboxdrv tool. Any other case that uses the /dev/input/eventXX
and that shows up in cat /proc/bus/input/devices
will also work.
#!/bin/bash
event="`sudo cat /proc/bus/input/devices | grep -Poz '("STK-7007F1"[\s\S]+?)\Kevent\d+'`"
echo $event #event26, for example
You may use other commands instead of echo. The "STK-7007FI" is how my controller is named when running cat /proc/bus/input/devices
. The script will throw a warning regarding a null char or something for some reason beyond my linux commands knowledge, but it works fine even with it.
The -Poz flag in grep is to use multiline regex. The \K is a working alternative for lookbehind. There may be better ways to do it, but that's what I came up with.
Upvotes: 1
Reputation: 704
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.
Upvotes: 31
Reputation: 11
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:
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
Upvotes: 1
Reputation: 897
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.
Upvotes: 17
Reputation: 71
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;}}}}'
Upvotes: 7
Reputation: 2916
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
Upvotes: 109