Last active
January 31, 2023 21:02
-
-
Save rbreaves/9a0a2bb8b0d6c2142acbbfa78c382262 to your computer and use it in GitHub Desktop.
hwdb udev Keyboard remap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original reference https://yulistic.gitlab.io/2017/12/linux-keymapping-with-udev-hwdb/ | |
systemd --version | head -n1 | awk '{print $2}' | |
# note systemd versions below 220 need | |
# keyboard:usb:v*p* | |
# 220 and above | |
# evdev:name:<name>:* | |
cat /proc/bus/input/devices | |
cat /proc/bus/input/devices | grep -B1 keyboard | head -n1 | |
cat /proc/bus/input/devices | grep -B1 keyboard | head -n1 | cut -c 8- | perl -p -e 's/(.\w+\=)/,/g' | |
// Grab all before match for multiple keyboards | |
cat /proc/bus/input/devices | awk '/eyboard/{for(i=2;i<=x;)print a[i++]}{for(i=1;i<x;i++)a[i]=a[i+1];a[x]=$0;}' x=2 | head -n2 | |
// Grab all after match for multiple keyboards | |
cat /proc/bus/input/devices | awk '/eyboard/{nr[NR+4]}; NR in nr' | awk -F"event" '/event/{print $2}' | head -n2 | |
awk '/eyboard/{for(i=1;i<=x;)print a[i++];print}{for(i=1;i<x;i++)a[i]=a[i+1];a[x]=$0;}' | |
cat /proc/bus/input/devices | awk '/eyboard/{for(i=2;i<=x;)print a[i++];print}{for(i=1;i<x;i++)a[i]=a[i+1];a[x]=$0;}' x=2 | |
cat /proc/bus/input/devices | awk '/eyboard/{for(i=2;i<=x;)if(i % 2 == 0){print a[i++];print}}{for(i=1;i<x;i++)a[i]=a[i+1];a[x]=$0;}' x=2 | |
cat /proc/bus/input/devices | grep -A2 keyboard | tail -n1 | awk '{print substr($0,length($0),1)}' | |
I: Bus=0011 Vendor=0001 Product=0001 Version=ab83 | |
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 leds event2 | |
B: PROP=0 | |
B: EV=120013 | |
B: KEY=402000000 3803078f800d001 feffffdfffefffff fffffffffffffffe | |
B: MSC=10 | |
B: LED=7 | |
sudo evtest /dev/input/event2 | |
evdev:input:b<bus_id>v<vendor_id>p<product_id>e<version_id>-<modalias> | |
// Built in keyboard | |
I: Bus=0011 Vendor=0001 Product=0001 Version=ab83 | |
// USB Keyboard - HOLTEK USB-HID Keyboard | |
I: Bus=0003 Vendor=04d9 Product=a131 Version=0111 | |
sudo vim /etc/udev/hwdb.d/99-keyboard.hwdb | |
------------------------- | |
// GUI mode | |
// Chromebook | |
evdev:input:b0011v0001p0001* | |
KEYBOARD_KEY_1d=leftalt | |
KEYBOARD_KEY_38=leftctrl | |
KEYBOARD_KEY_db=leftmeta | |
// USB keyboard | |
evdev:name:HOLTEK USB-HID Keyboard:* | |
KEYBOARD_KEY_700e0=leftmeta | |
KEYBOARD_KEY_700e3=leftalt | |
KEYBOARD_KEY_700e2=leftctrl | |
----------------------------------- | |
// Remote macOS mode | |
// Chromebook | |
evdev:input:b0011v0001p0001* | |
KEYBOARD_KEY_1d=leftalt | |
KEYBOARD_KEY_38=leftmeta | |
KEYBOARD_KEY_db=leftctrl | |
// USB keyboard | |
evdev:name:HOLTEK USB-HID Keyboard:* | |
KEYBOARD_KEY_700e0=leftctrl | |
KEYBOARD_KEY_700e3=leftalt | |
KEYBOARD_KEY_700e2=leftmeta | |
----------------------------------- | |
// Normal Mode | |
// Chromebook | |
evdev:input:b0011v0001p0001* | |
KEYBOARD_KEY_1d=leftctrl | |
KEYBOARD_KEY_38=leftalt | |
KEYBOARD_KEY_db=leftmeta | |
// USB keyboard | |
evdev:name:HOLTEK USB-HID Keyboard:* | |
KEYBOARD_KEY_700e0=leftctrl | |
KEYBOARD_KEY_700e3=leftmeta | |
KEYBOARD_KEY_700e2=leftalt | |
----------------------------- | |
sudo systemd-hwdb update | |
sudo udevadm trigger | |
----------------------- | |
KEYBOARD_KEY_<scan_code>=<key_code> | |
Event code 29 (KEY_LEFTCTRL) | |
Event code 56 (KEY_LEFTALT) | |
Event code 97 (KEY_RIGHTCTRL) | |
Event code 100 (KEY_RIGHTALT) | |
Event code 125 (KEY_LEFTMETA) | |
Event code 126 (KEY_RIGHTMETA) | |
Event code 127 (KEY_COMPOSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment