Linux – xkb set keyboard level 3 chooser to ctrl+alt

keyboardlinuxxfcexkb

The title says it all: I'm interested to mimic the Windows behavior, where Left Ctrl + Left Alt acts as a 3rd level chooser. This is relatively important to me, because, as a programmer, on my keyboard layout, important symbols such as {,[,] or } are accessible only by pressing Right Alt + Key, which is extremely uncomfortable using only one hand. At the moment, I use both Alt keys as a level 3 chooser, but this has some unwanted consequences, as I am no longer able to input some shortcuts(e.g. Home in Firefox).

I am on openSuse 13.1, using XFCE as a desktop environment. This question has already been asked a couple of times, but unfortunately no answer was provided in any of them, and the documentation on xkb is pretty scarce.

Best Answer

The following solution is barbaric, but it works (provided you're satisfied with a Level3 Latch instead of a Level3 Shift — the difference is that with the latter all the keys have to be pressed at the same time, while with the former you first press LeftCtrl+LeftAlt, release this and only then press the key to be shifted) and does not require root.

setxkbmap -option grp:lctrl_lalt_toggle

xmodmap -e 'keycode  37 = Control_L ISO_Level3_Latch'
xmodmap -e 'keycode  64 = Alt_L ISO_Level3_Latch'

Explanation for how this works:

The xkb grp:lctrl_lalt_toggle option makes LeftCtrl shift LeftAlt to level2 and vice-versa (see: /usr/share/X11/xkb/symbols/group). It also makes the level2 shift of LeftCtrl and LeftAlt to be ISO_Next_Group, which is undesirable, since we want this to be ISO_Level3_Latch, hence we use xmodmap to change the level2 to ISO_Level3_Latch for both LeftCtrl and LeftAlt (while keeping level1 as Control_L and Alt_L). The keycodes (37 and 64) can be found either by inspecting the output of xmodmap -pke or by using xev.

If we only applied the xmodmap redefinitions (without using setxkbmap first) then the key responsible for the level2 shift would be Shift, as it is for almost all keys, so both Shift+LeftCtrl and Shift+LeftAlt (but not LeftCtrl+LeftAlt) would become Level3 Latches.

Why do we have to use a Level3 Latch rather than a Level3 Shift?

If you were to use ISO_Level3_Shift rather than ISO_Level3_Latch, you you would have to simultaneously press LeftCtrl+LeftAlt+YourDesiredKey, for the level3 shift to occur. Unfortunately, LeftCtrl and LeftAlt still remain modifiers, so apart from YourDesiredKey being correctly shifted, it would also be "modified" by one of Alt or Ctrl (depending on which you pressed first). With the latch, you don't have this problem.

Related Question