Swap some keyboard keys

Turns out, you can remap keys in the Linux kernel.

  1. Determine the scan code of the key you want to remap to be some other key. This will be a hexadecimal number and you can see it in sudo showkey -s. Be careful, the program will emit both the codes for the keypress event and the release. Let's say I want to change the behavior of the 0xe021 key (Calculator on my keyboard.)
  2. Determine the key code of the key you want your key to behave as. This will be a decimal number and you can get it with sudo showkey -k. Be careful, the program will emit both the codes for the keypress event and the release. Let's say I want to have another '107' key (End on my keyboard.)
  3. Issue sudo setkeycodes e021 107, with your codes.
  4. To make it permanent you have to run it after each boot as root. You can solve it with crontab. Run sudo crontab -e and put your command from above at the end of the file (without sudo but with absolute path): /usr/bin/setkeycodes e021 107