1

I have done quite a lot of research on how to swap the Escape and Caps Lock keys. I achieved it while using X11 via my .xinitrc file and the following line of code:

setxkbdmap -option caps:swapescape

However, when I start a tty, it doesn't work. How can I get this to work while using a tty? Is it possible to use some kind of global option, like a custom keyboard layout that does not depend on X11?

I'm using Arch Linux, if that helps.

  • [How to change console keymap in Linux?](https://superuser.com/questions/290115/how-to-change-console-keymap-in-linux). – Quasímodo Oct 25 '20 at 10:49
  • The output of `dumpkeys | head -1` shows `keymaps 0-2,4-6,8-10,12` for my current keyboard layout (de-latin1), should I put that output or the suggested output of `keymaps 0-127` in the file? – Peter Arbeitsloser Oct 25 '20 at 10:58
  • Also, why is it called CtrlL_Lock and not Caps_Lock? – Peter Arbeitsloser Oct 25 '20 at 10:59
  • I'm not using Arch Linux, but maybe try adding `XKBOPTIONS="ctrl:nocaps"` to `/etc/default/keyboard` (it works in Debian with both vts and xorg). Otherwise, you can do it by hand with `dumpkeys | sed 's/keycode *58 =.*/keycode 58 = Control/' | loadkeys` (you may have to adjust the sed expression, check with `showkey` and `dumpkeys | less` before). –  Oct 25 '20 at 12:56
  • Sorry, that was about `nocaps` ;-) but it may still give you the idea how to tackle `swapescape` too. –  Oct 25 '20 at 12:59
  • The file doesn't exist, should I create it? – Peter Arbeitsloser Oct 25 '20 at 13:58
  • If it doesn't exist, then it means that Arch Linux isn't using it. Try the manual method instead. –  Oct 25 '20 at 14:21
  • Where should I put that code? – Peter Arbeitsloser Oct 25 '20 at 14:35
  • A related question is https://unix.stackexchange.com/q/479673/5132 . – JdeBP Oct 25 '20 at 15:20
  • Though not very clean, you can put in `/etc/profile` or `/etc/profile.d/`, and make it conditional on the type of terminal: `[ "$TERM" = linux ] && dumpkeys | ... | loadkeys`. –  Oct 25 '20 at 15:29
  • @JdeBP The thing is, the only answer was about how to do it in debian and I'm using Arch, where the /etc/default/keyboard file doesn't exist... – Peter Arbeitsloser Oct 25 '20 at 15:31
  • Okay, changed the question, because I did it for **X11**. Now I just need to do it for **tty**. Any ideas? – Peter Arbeitsloser Oct 25 '20 at 16:09
  • This is not a duplicate question and actually might have some value for others. – Peter Arbeitsloser Jan 27 '21 at 13:26

1 Answers1

0

Step by step solution

X11

The following command sets the X11 keyboard correctly (de is my keyboard layout):

localectl --no-convert set-x11-keymap de "" "" caps:swapescape

tty

The tty keyboard can be configured as follows:

  1. Copy the correct keyboard layout file to a custom directory:

cp /usr/share/kbd/keymaps/i386/qwertz/de-latin1.map.gz /usr/local/share/kbd/keymaps

(You will have to change that command depending on what keyboard layout you are using)

  1. Change every occurency of Escape to Caps_Lock and every occurency of Caps_Lock to Escape in the copied file and rename it to something like de-latin1-custom.map.gz

  2. Edit the /etc/vconsole.conf file to look like this:

KEYMAP="/usr/local/share/kbd/keymaps/de-latin1-custom.map.gz"

After rebooting the system the keyboard should be configured correctly for X11 and for tty.