DEV Community

Robin Kretzschmar
Robin Kretzschmar

Posted on

Arch Linux remap keys for 80% keyboard

The story behind it

Skip this section if you just want to know the implementation, no one will judge you :)

After the keycaps on my mechanical keyboard became more worn down year by year, I decided to peak into r/MechanicalKeyboards for some inspiration.

After reading a lot about the different switches and boards, I decided to by an 80% keyboard (a Royal Kludge RK84 to be precise).

As I am german and require an ISO keymap, I wanted to buy custom keycaps with the ISO lettering. But the keyboard arrived before I had made up my mind which keycaps to buy and so I gave it a try with the US keycaps.

Everything seemed to work fine, even the german "Umlaute" (ö,ä,ü,ß) are properly recognized by my Arch installation. And if we are being honest: after some days of typing I knew which key and combination is what so I don't really need to look at the keycaps anymore now.

But one thing bothered me:
The "greater than" and "less than" symbols were impossible to produce for me.
I tried every combination there is but I only got double side arrows with alt+Z and alt+X.
It looked like this:

»
«
Enter fullscreen mode Exit fullscreen mode

After reading a bit in the Arch wiki, I decided to remap my keys for this purpse.

The remapping

Check the current mapping

The first thing to do is to check the current mappings with this command:

xmodmap -pke
Enter fullscreen mode Exit fullscreen mode

This gives a similar output to this:

...
keycode  52 = y Y y Y guillemotright U203A guillemotright
keycode  53 = x X x X guillemotleft U2039 guillemotleft
...
Enter fullscreen mode Exit fullscreen mode

As seen in this output, the keys are mapped to unicode signs for "SINGLE RIGHT-POINTING ANGLE QUOTATION MARK" and "SINGLE LEFT-POINTING ANGLE QUOTATION MARK". You can check the unicode values at fileformat.info unicodes by changing the code in the URL to the one you want to check (without the leading U that just indicates that this is unicode).

Find keycodes you want to change

If you search for the keys you want to remap in the output, you'll find the keycode. Copy the whole line you want to change as you'll adjust only the parts you want to remap.

Another way to find the keycode to look for is to use the command

xev -event keyboard
Enter fullscreen mode Exit fullscreen mode

which opens a window that captured your input from the keyboard and displays the keycodes in the console.

For this example, I would copy the 2 lines shown above.

Remap on the fly

To remap the keys, replace the mapping string and apply the changes like this:

xmodmap -e "keycode 52 = y Y y Y guillemotright U003E guillemotright"
xmodmap -e "keycode  53 = x X x X guillemotleft U003C guillemotleft"
Enter fullscreen mode Exit fullscreen mode

You can try it immediately.

Persist the mapping

Now to ensure this new mapping stays persistent if you ever switch the USB port your keyboard is connected to or had it connected to another maschine in between, you should persist the new mapping.

Store them with: xmodmap -pke > ~/.Xmodmap
Xorg server will pick up the file by itself, but to ensure you have the same settings for terminal sessions, add the following lines to your ~/.xinitrc:

usermodmap=$HOME/.Xmodmap

if [ -f "$usermodmap" ]; then
    xmodmap "$usermodmap"
fi
Enter fullscreen mode Exit fullscreen mode

Top comments (0)