Skip to content

Instantly share code, notes, and snippets.

@Syakhisk
Created August 6, 2021 22:55
Show Gist options
  • Save Syakhisk/c1edac6d1b8e36b387a6b6caa02f9d92 to your computer and use it in GitHub Desktop.
Save Syakhisk/c1edac6d1b8e36b387a6b6caa02f9d92 to your computer and use it in GitHub Desktop.
Switch Backtick/Tilde Key to Escape Key (Keychron K6/Other Small Keyboard)

Switch Backtick/Tilde Key to Escape Key (Keychron K6/Other Small Keyboard)

Small keyboards (+- 68 keys) will join the F rows as well as the Escape key to the numbers row, since this bothers me so much, I wanted to remap the backtick to Escape key BUT only on this keyboard (other keyboard will have their normal mapping).

After scouring on the internet for hours I made this gist you don't have to go through what I did.

Install evtest

sudo pacman -S evtest # Arch based
sudo apt install evtest # Debian based

Locate your keyboard in /dev/input/by-id/

ls /dev/input/by-id

Find something like usb-Keychron_Keychron_K6-* (depends on your keyboard)

Run evtest

evtest /dev/input/by-id/usb-Keychron_Keychron_K6-event-kbd

Press your key (Escape, and then backtick)

Testing ... (interrupt to exit)
Event: time 1628290151.645272, type 4 (EV_MSC), code 4 (MSC_SCAN), value __70035__
Event: time 1628290151.645272, type 1 (EV_KEY), code 1 (KEY_ESC), value 1
Event: time 1628290151.645272, -------------- SYN_REPORT ------------
^[Event: time 1628290151.778901, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70035
Event: time 1628290151.778901, type 1 (EV_KEY), code 1 (KEY_ESC), value 0
Event: time 1628290151.778901, -------------- SYN_REPORT ------------
Event: time 1628290154.048148, type 4 (EV_MSC), code 4 (MSC_SCAN), value __70029__
Event: time 1628290154.048148, type 1 (EV_KEY), code 41 (KEY_GRAVE), value 1
Event: time 1628290154.048148, -------------- SYN_REPORT ------------
`Event: time 1628290154.139326, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70029
Event: time 1628290154.139326, type 1 (EV_KEY), code 41 (KEY_GRAVE), value 0
Event: time 1628290154.139326, -------------- SYN_REPORT ------------

Now we know the keyscan of Escape is 70035 and backtick is 70029

Note down the bus, vendor, and product hex value from the TOP of the evtest output and convert them to 4 digit with uppercase:

❯ evtest /dev/input/by-id/usb-Keychron_Keychron_K6-event-kbd 
Input driver version is 1.0.1
Input device ID: bus _0x3_ vendor _0x5ac_ product _0x24f_ version 0x111
Input device name: "Keychron Keychron K6"
Supported events:

bus - 0x3 - 0003 vendor - 0x5ac - 05AC product - 0x24f - 024F

Create a file in /etc/udev/hwdb.d/10-keyboard-switch and change the numbers accordingly:

# b = bus, v = vendor, p = product
evdev:input:b0003v05ACp024F*
 KEYBOARD_KEY_70029=grave # map Escape to grave(backtick)
 KEYBOARD_KEY_70035=esc # map grave(backtick) to Escape

And then update the hwdb and udev

sudo systemd-hwdb update && sudo udevadm trigger

Done, Tested on Arch Linux.


References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment