User:Riviera/Fixing a keyboard bug

From XPUB & Lens-Based wiki

As wonderful as Linux is, it can also be frustrating to work with. In other words, my computer has a bug and it’s bugging me. Here’s the problem: there is an incongruity between the default keymap and the physical keyboard layout. For example, when I press the ~ key on the keyboard inside a tty, it produces ¬. When I press the # key the machine returns £. This suggests that the keymap is defaulting to a UK layout whereas the physical keyboard has a US layout. This is not a problem when I am using X11, only the ttys have this problem.

Why fix this bug?

I’d like to do a live coding performance inside a tty. This assumes it is possible to connect a projector to the computer via VGA and “mirror” the tty. I think that’s doable but I’ll have to test it. If it is possible, it’s helpful to have the console keymap correctly set up. Primarily this would enable me to make use of the pipe character which I currently have no idea how to input. This character sometimes appears in code and is pragmatic to have access to. Another reason to fix the bug is that habitual computer use has led me to expect symbols to be in various places. I find it distracting when the computer returns unintended output on some keypresses.

How have I tried to fix this bug?

I have tried various methods in order to resolve this issue. Initially, I experimented with sudo dpkg-reconfigure keyboard-configuration. This did not work. I then attempted to install the console-data package, which also did not work. Thirdly, I used the localectl command to list available keymaps. There were none available. I therefore installed them from source using a recent version of the kbd package to /usr/share/keymaps. This allowed me to use the command sudo loadkeys us to emulate a US layout for the duration of one session. I attempted, following the Arch Linux wiki, to make the US layout persist across tty sessions. However, I was unable to do this using the localectl command. I therefore manually edited /etc/vconsole.conf, providing different values to the KEYMAP variable. Each time I rebooted it did not work as expected.

How I fixed the bug

Eventually I found a solution on StackExchange. The trick was to give non-root users access to the loadkeys command. This involved creating a group called loadkeys and adding my user to this group. I then placed loadkeys /path/to/us.map in ~/.bashrc so that the correct keymap is loaded on login.