If you search the web for “remap keys ubuntu”, you’ll find a dizzying collection of contradictory articles on the subject. This is one of those simple questions that seems to have a complicated answer, because of the long legacy of remapping keys on various distributions of Linux over the decades. I found many many ways to do it, not all equivalent, and with a complicated variety of consequences, most of which I do not understand yet. This makes it easy to find answers, but difficult to find answers that fit you well. It seems like one needs to get a Ph. D. in Linux to find an answer that you’ll feel comfortable with.
Of course, if you want to learn more about the boundaries between the operating system and your desktop environment, remapping keys provides an effective way to learn some part of that. I do not—at least not today.
And if you’re like me, you’ll forget about how you remapped your keys, then you’ll wake up one morning after a software update, your keyboard layout will have been reset, and you won’t remember how to fix it.
My Primary Goal
I wanted a solution that allowed me to put my keyboard configuration in version control, so that I knew exactly how to reapply my keyboard mapping any time it changed on me. I wanted the ability to do this quickly and easily.
Rather than wade through all the options available to me, I asked System 76 support what they recommended to me, and I really like their recommendation, at least for now, as of late 2022.
My Current Solution
I use the package
system76-keyboard-configurator, which provides two things that I like:
- a GUI to remap the keys, so that I can see what I’m doing
- an import/export feature, so that I can store my configuration in a text file (JSON format) that I can put in version control (git).
The whole exercise took about 1 minute.
This software changes the keymap at the firmware level, which I infer means that these changes apply before any changes I’ve made in Gnome, whether using the keyboard settings or Gnome Tweaks. I’ll keep an eye out for whether this causes any problems.
If anything behaves strangely, I’ll probably prefer to move the keyboard mappings out of Gnome and into the firmware. For example, I want my
Caps Lock key to behave like
Control all the time, and not only when I’m running Gnome.
Of course, I’ll need to look for a different solution when I’m working on a Linux machine that doesn’t come from System76, but the only reason I need this is that my Lemur Pro 10 laptop keyboard has a
Prt Sc key and no
Insert key, but I am used to using the keystroke
Alt+Insert quite often in IntelliJ IDEA. In an emergency, I can always change the keystroke in IDEA; in general, I don’t need
Prt Sc, because I use a screenshot tool such as Spectacle.
$ sudo apt-get install system76-keyboard-configurator$ system76-keyboard-configurator
This launches the GUI.
- Press “Configure Keyboard”.
- Remap the keys, as you like.
- From the menu, choose “Export Layout”.
This produces a JSON format text file that you can store anywhere you like. I put mine in my
dotfiles repository, even though it’s not really a dotfile.
As a test, I used the application to reset my keymap, then import my custom layout. This worked great!
https://github.com/pop-os/keyboard-configurator I installed the release published into
apt, but it looks pretty easy to run this application directly from source, if you prefer.
“Configuring your new Launch keyboard”. I didn’t figure this out myself, mostly because this article doesn’t make it easy to notice that I can use the Keyboard Configurator on my laptop’s keyboard. When I skimmed this article, I assumed that one would use this tool only with a Launch keyboard, which I don’t have.