Remapping keyboard without firmware modification (adding SysRq key)

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:


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


This is very cool, thanks!

Interesting, knew about that for other keys but didn’t think it’d work for sysrq as I was thinking that was handled at a lower level than evdev. Interesting to know that works for this. Benefit of changing the keyboard firmware could be in adding it as a secondary layer key like under the MNT key or Hyper key

I originally considered the approach with a second layer as well. As there is currently no fn-style key in the firmware, one would have to change the logic a bit first. I couldn’t really come up with any other keys I would want to add (except maybe home+insert but those I rarely ever use) so it didn’t seem worth the effort. Do you see any keys that would be useful and are currently missing?

However, for the standalone mnt keyboard this might generally be a different story: one might want to connect this to random computers on different OSs and expect to be able to reach all keys and functions without any reconfiguration. So a second layer would certainly be nice in that use case. For my reform, I think this solution is good enough for me at the moment :slight_smile: