Rtodev.tech blog

Keyboard mappings

I'm doing experiments on minimal usage of my laptop. I wonder if I can avoid using X. My main issue was to be able to switch keyboard mapping, between fr and en. On X11, I use command setxkbmap. I was not used to do it on console though, since I only use it when I have an issue on X11. So I found to ways.

The hardway: localectl

It seems that on systemd based system, command localectl is available. It allows to change the mapping with

sudo localctl set-keymap us

Typing localectl without args show the actual configuration.

System Locale: LANG=fr_FR.UTF-8 VC Keymap: fr X11 Layout: fr X11 Model: pc105 X11 Variant: latin9 X11 Options: terminate:ctrl_alt_bksp

The thing is the modification is persistent and also modify X11 configuration. It's not applied right away on the console though. To apply your changes, you have to run:

sudo setupcon

It works! But having to type 2 commands with sudo is far to be has convenient than using setxkbmap.

Thankfully, there is a better way.

The not so hard way: loadkeys

I found here and there on the Internet that I can use loadkeys to change mapping on console. Unfortunately, that does not work on Debian (11), the charmaps are not where the docs say they should be… I found that's because I needed to install package console-data

sudo apt install console-data

And then following command work:

sudo loadkeys us

There is a lot of available keymaps in /usr/share/keymaps/i386 onceconsole-data` is installed, feel free to use your favorite weird dvorak based keymap.

Unfortunately though, I need to run this as root as it deals with some console specific system wide file descriptor.

To conclude

I'm glad I can change keyboard mapping on console: no X11 was involved during the writing of this piece!

Posted on 2022-05-07 at 00:35

Previous Back Next