-
Notifications
You must be signed in to change notification settings - Fork 248
Match device using udev
Kindly written by Chris Vogel (@chri2), explaining how can a specific device be matched with a udev rule, so you can differentiate between multiple devices on the same machine:
On my system the default udev rules do not include the information about the serial number when asking the hardware database for extra information about a device.
/etc/udev/rules.d/59-evdev.rules:
ACTION=="remove", GOTO="evdev_end"
KERNEL!="event*", GOTO="evdev_end"
# Device matching the input device name and the S/N (used for Deskhop)
KERNELS=="input*", \
IMPORT{builtin}="hwdb 'evdev:sn:$attr{name}:$attr{uniq}'", \
ENV{.HAVE_HWDB_PROPERTIES}="1"
LABEL="evdev_end"
The filename is chosen, so that this rule would run before my default rule for evdev named /lib/udev.d/rules/60-evdev.rules. You might need to change the filename for your system accordingly. /lib/udev.d/rules/60-evdev.rules contains IMPORT{builtin}="keyboard" which should run after the new rule.
The device match above will lookup the hardware database for a section evdev:sn:<deskhop name>:<deskhop s/n>. I added it to the database:
/etc/udev/hwdb.d/59-keyboard.hwdb:
# deskhop with S/N
evdev:sn:Hrvoje Cavrak DeskHop Switch Keyboard:xxxxxxxxxxxxxxxxx
KEYBOARD_KEY_7004a=insert
KEYBOARD_KEY_70049=home
To get the xxxxxxxxxxxxxxxxx part (serial number) I used lsusb -d2e8a:107c -v | grep -i serial which outputs something like
# lsusb -d2e8a:107c -v | grep -i serial
iSerial 3 xxxxxxxxxxxxxxxxx
The first digit seperated by space from the S/N is not part of the number - in my example the 3.