Petri Kannisto's homepage – about software systems and research

Map keyboard keys in Linux Mint/Ubuntu with XKB

– Petri Kannisto


My nice (and expensive!) Lenovo Thinkpad T14S AMD (gen 1) has an annoying defect, namely the enter and backspace keys on the internal keyboard stop working randomly. This occurred multiple times and went away, but now the defect seems to persist. As a temporary workaround, they suggest to press backspace and/or enter for 5-10 seconds or to press them multiple times, but this seems not to help anymore. Before I find the time to see if the machine still has some warranty left, I wanted to try something.

The missing backspace has multiple short-term workarounds, at least selecting text and then just typing or using the delete key, but enter has none unless the current user interface has a respective mouse button. You could also copypaste the newline in some occasions.

Remap right CTRL to enter

For a better workaround for the missing enter, I decided to re-map right CTRL for this. The XKB (X Keyboard) system, which seems to be in use by default at least in Linux Mint and Ubuntu, enables you to make remappings. Googling revealed some commands that seem complex but really aren't. In the end, it seems you just have to edit a text file with the correct content.

!!! It seems XKB can mess up your system badly so better to take a system backup with Timeshift!

Combining the forum threads Add keyboard shortcut for Enter and I Messed up my Keyboard while trying to remap a Key, I knew what symbol is right CTRL (i.e., RCTL), what is enter (Return) and which file to edit and on what line (30 in this case). It also helped to observe the pc file being edited to understand what's actually going on.

I ended up with this command:

sudo sed -i '30s|.*|key<RCTL>{[Return]};|' \
/usr/share/X11/xkb/symbols/pc \
&& sudo dpkg-reconfigure xkb-data

The tricky part was to give the sudo password without enter. The workaround was to copypaste a newline from the text editor. An external keyboard would help too, but I happened to have none at hand.

Then, I rebooted the machine, and right CTRL gave me the enter key right from the login screen! Now I can at least use the machine, still annoyed and hoping that the warranty has not expired yet.

However, if the attempt fails and your keyboard gets messed up, this thread likely helps: I Messed up my Keyboard while trying to remap a Key.