I have just added the SysRq key (useful when debugging system issues) to my keyboard by remapping the scancode of the F12 key to the SysRq keycode using udev. Of course, you could apply this to other keys as well. This works without modifying the keyboard firmware and might be useful for others, so I thought I’d summarize it here.
A good guide can be found here: Map scancodes to keycodes - ArchWiki
First, install the evtest
tool through sudo apt install evtest
. Now run sudo evtest
and press the key you want to remap. Please note: this works on raw scancodes meaning you cannot map key combinations! If you want to add e.g. special characters to your keyboard layout, check out Home · swaywm/sway Wiki · GitHub.
evtest
will give you output like:
Event: time 1641577283.217286, type 4 (EV_MSC), code 4 (MSC_SCAN), value 70045
when you press a key. The value 70045 here is for F12 and needs to be noted down. Quit by pressing ctrl-c
Now create a new udev hardware description, e.g.
sudo nano /etc/udev/hwdb.d/90-keyboard-mapping.hwdb
with the following content:
evdev:input:b0003v03EBp2042*
KEYBOARD_KEY_70045=sysrq
The first line identifies the internal MNT reform keyboard (see first link for details) and the second line maps the key with the scancode 70045 (F12) to a new key, here SysRq. Be careful that you have exactly one space in front of the second line! You can also remap to other keycodes. The corresponding names can be found in /usr/include/linux/input-event-codes.h
just use the part after the KEY_
prefix in lowercase.
Now, run sudo systemd-hwdb update
and sudo udevadm trigger
to update the hardware database and to trigger an udev update. Now, the remapped key should register as SysRq and you can access the kernel’s “magic SysRq commands” by pressing alt-F12-[command]: Linux Magic System Request Key Hacks — The Linux Kernel documentation