Xorg: How can I map AltGr to the CapsLock Key (to toggle 3rd level symbols)

I know this question is old, but if anyone stumbles across it again, there is an alternative solution:

setxkbmap -option "lv3:caps_switch"

For a full list of options, read the "OPTIONS" section of

man xkeyboard-config

Based on Dennis' answer and by playing around with xev I found out that the magic phrase seems to be ISO_Level3_Shift.

At least this works for me:

xmodmap -e "keycode 66 = ISO_Level3_Shift"

Now I dont' run into danger to break my fingers while typing [, ], {, } and co on my german keyboard layout.

Edit: now using the -e option of xmodmap


Long's answer is the best one for modern Desktops like Gnome, because Gnome itself uses xkb and overwrites xmodmap configurations by default (also, xmodmap is on its way out and unsupported in Wayland). Unfortunately, it will still only work until reboot.

You can apply this option permanently for your Gnome desktop with this command:

gsettings set org.gnome.desktop.input-sources xkb-options "['lv3:caps_switch']"

Of course you can also make this change permanently and even system wide, without using Gnome. If you use Gnome, you should still use the above command to keep Gnome from overwriting this setting. For Arch, you can add a file /etc/X11/xorg.conf.d/90-custom-kbd.conf with the following content:

Section "InputClass"
    Identifier "keyboard defaults"
    MatchIsKeyboard "on"
    Option "XKbOptions" "lv3:caps_switch"
EndSection

I assume this differs between distributions, so your mileage might vary.