Score:1

Swap some keyboard keys

us flag

I would like to swap some keys, like Home and End on my keyboard. I did it using xmodmap, but this gets reverted every time my computer goes to sleep, and some applications, e. g. VSCode don't respect it.

Is there any way to permanently swap keys and make each app detect it right?

I'm using Ubuntu 20.04.

Score:1
us flag

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
Liso avatar
sd flag
Very helpful ! +1
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.