Off-Topic > Off-Topic - Tiny Core Lounge

how to automatically get xinput id of keyboard?

(1/5) > >>

GNUser:
I've written a shell script that needs to know the xinput id of the keyboard being used. In the case of my TC 10.1 and Devuan boxes, the id happens to be 9. However, in my OpenBSD box the id is 6.

I want to make the script portable and don't want to bother myself or other users with having to run xinput --list and then manually editing the keyboard id in the script. Is there a way to determine the id automatically? If the script has to wait for user to press a key so that script can find the id, that would be fine.

grepping output of xinput --list for "keyboard" won't work because there's more than one line with that word in it. Also, I don't want to assume that the system language is English.

Rich:
Hi GNUser
The contents of  /proc/bus/input/devices  might have some interesting content:

--- Code: ---tc@box:~$ cat /proc/bus/input/devices
I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=PNP0C0C/button/input0
S: Sysfs=/devices/LNXSYSTM:00/device:00/PNP0C0C:00/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0

I: Bus=0019 Vendor=0000 Product=0001 Version=0000
N: Name="Power Button"
P: Phys=LNXPWRBN/button/input0
S: Sysfs=/devices/LNXSYSTM:00/LNXPWRBN:00/input/input1
U: Uniq=
H: Handlers=kbd event1
B: PROP=0
B: EV=3
B: KEY=100000 0 0 0

I: Bus=0011 Vendor=0001 Product=0001 Version=ab41
N: Name="AT Translated Set 2 keyboard"
P: Phys=isa0060/serio0/input0
S: Sysfs=/devices/platform/i8042/serio0/input/input2
U: Uniq=
H: Handlers=sysrq kbd event2
B: PROP=0
B: EV=120013
B: KEY=4 2000000 3803078 f800d001 feffffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0011 Vendor=0002 Product=0006 Version=0006
N: Name="ImExPS/2 Logitech Explorer Mouse"
P: Phys=isa0060/serio1/input0
S: Sysfs=/devices/platform/i8042/serio1/input/input3
U: Uniq=
H: Handlers=mouse0 event3
B: PROP=0
B: EV=7
B: KEY=1f0000 0 0 0 0 0 0 0 0
B: REL=143

I: Bus=0010 Vendor=001f Product=0001 Version=0100
N: Name="PC Speaker"
P: Phys=isa0061/input0
S: Sysfs=/devices/platform/pcspkr/input/input4
U: Uniq=
H: Handlers=kbd event4
B: PROP=0
B: EV=40001
B: SND=6

tc@box:~$
--- End code ---

GNUser:
Thanks for that, Rich. Interesting. However, I don't see the xinput ids listed in there.

Meanwhile I found this https://unix.stackexchange.com/questions/89538/how-to-tell-which-keyboard-was-used-to-press-a-key

The above comes close, but having to ship a C program with my shell script is not an option. I need to figure out a way to find the id using native X tools, even if the script has to wait for a key to be pressed.

Rich:
Hi GNUser
This should get you into the ballpark:

--- Code: ---tc@E310:~$ cat /proc/bus/input/devices | grep -i keyboard
N: Name="DELL DELL USB Keyboard"
tc@E310:~$ xinput list --id-only "DELL DELL USB Keyboard"
9
tc@E310:~$
--- End code ---

GNUser:
Beautiful! Thank you. That worked in every Linux box I tried.

I also found this solution, which works in the BSDs as well because it does not rely on info provided by the linux kernel:


--- Code: ---xinput --list --long | grep XIKeyClass | head -n 1 | egrep -o '[0-9]+'
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version