Remap keys in Linux.
My new keyboard has an American layout. Since I type blind, no problem so far, but the key for <, > and | is missing. The problem is that it’s not somewhere else, it’s missing.
What to do?
My idea was to use a different button for this. One button that would work well for this is the Caps Lock button. I don’t use it anyway and I think the key is superfluous anyway.
The solution was quite simple under Windows, where I could simply reconfigure the key with “KeyTweak“. That was done in 5 minutes.
Linux is a bit more challenging. Here there is the software “Xmodmap“. This can in principle reconfigure keys, but has a few limitations, more on this later.
First we create the configuration data:
vim ./Xmodmap
Here is the content of the file, please note this is the german layout:
clear Lock keycode 108 = Mode_switch Mode_switch Mode_switch Mode_switch keycode 66 = less greater bar bar keycode 24 = q Q at keycode 26 = e E EuroSign keycode 35 = plus asterisk asciitilde keycode 11 = 2 quotedbl twosuperior keycode 12 = 3 section threesuperior keycode 16 = 7 slash braceleft keycode 17 = 8 parenleft bracketleft keycode 18 = 9 parenright bracketright keycode 19 = 0 equal braceright keycode 20 = ssharp question backslash
Let’s take a brief look at the content. With the first line we switch off the standard function of Caps-Lock. Otherwise, Caps-Lock is still activated additionally.
The second line with the “Mode_switch” remaps the ALT-GR key. This is needed to get the | character. ALT-GR causes minor problems with Xmodmap.
The third line then maps Caps-Lock to our desired characters. The syntax is normal, then with Shift and then the value for the modifier key.
What do the other lines do? Well, reconfiguring ALT-GR has the side effect that the other characters generated with ALT-GR no longer work. These include the euro, at sign and the tilde. We therefore configure these keys with .
We can determine the keycode with the “xev” command. Simply start this via the console and then press the key. The code is in the third line.
KeyRelease event, serial 38, synthetic NO, window 0x8600001, root 0x3d0, subw 0x0, time 7427147, (1301,516), root:(1391,678), state 0x10, keycode 35 (keysym 0x2b, plus), same_screen YES, XLookupString gives 1 bytes: (2b) "+" XFilterEvent returns: False
As soon as we have saved the file, we can activate it:
xmodmap ~/.Xmodmap
Caps-Lock should be deactivated beforehand. If you have made a mistake and the configuration is rubbish, you can undo it with the following command.
setxkbmap option
The setting is only valid until the next restart. It is therefore advisable to include the call for the setting in the login script.
So far it works quite well. I hope I haven’t overlooked an ALT-GR key, but this can otherwise be extended quite easily.