Skip to content

Instantly share code, notes, and snippets.

@rbreaves
Last active January 31, 2023 21:02
Show Gist options
  • Save rbreaves/9a0a2bb8b0d6c2142acbbfa78c382262 to your computer and use it in GitHub Desktop.
Save rbreaves/9a0a2bb8b0d6c2142acbbfa78c382262 to your computer and use it in GitHub Desktop.

Revisions

  1. rbreaves revised this gist Mar 23, 2020. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions hwdb udev keyboard.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,13 @@

    # 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
  2. rbreaves renamed this gist Mar 23, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. rbreaves revised this gist Mar 23, 2020. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -32,8 +32,6 @@ B: LED=7

    sudo evtest /dev/input/event2

    sudo vim /etc/udev/hwdb.d/99-keyboard.hwdb

    evdev:input:b<bus_id>v<vendor_id>p<product_id>e<version_id>-<modalias>

    // Built in keyboard
    @@ -42,9 +40,9 @@ I: Bus=0011 Vendor=0001 Product=0001 Version=ab83
    I: Bus=0003 Vendor=04d9 Product=a131 Version=0111


    keyboard:usb:v*p*
    sudo vim /etc/udev/hwdb.d/99-keyboard.hwdb
    -------------------------
    GUI mode
    // GUI mode

    // Chromebook
    evdev:input:b0011v0001p0001*
    @@ -59,7 +57,7 @@ evdev:name:HOLTEK USB-HID Keyboard:*
    KEYBOARD_KEY_700e2=leftctrl

    -----------------------------------
    Remote macOS mode
    // Remote macOS mode

    // Chromebook
    evdev:input:b0011v0001p0001*
    @@ -75,7 +73,7 @@ evdev:name:HOLTEK USB-HID Keyboard:*

    -----------------------------------

    Normal Mode
    // Normal Mode

    // Chromebook
    evdev:input:b0011v0001p0001*
    @@ -89,12 +87,12 @@ evdev:name:HOLTEK USB-HID Keyboard:*
    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)
  4. rbreaves created this gist Mar 23, 2020.
    106 changes: 106 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,106 @@

    # Original reference https://yulistic.gitlab.io/2017/12/linux-keymapping-with-udev-hwdb/

    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

    sudo vim /etc/udev/hwdb.d/99-keyboard.hwdb

    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


    keyboard:usb:v*p*
    -------------------------
    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)