I have found enabling sticky keys under xorg (awesome desktop manager) on Super User, which showed me that I can enable sticky keys via

xkbset sticky -twokey

This works as expected, but in my case I'd prefer to only make a specific key (Alt Gr) be sticky instead of all modifier keys. Can this be configured? And if so: where?

1 Answer 1


On X11 one way to achieve that is by using XKB and making the right alt key set the current latch mode as AltGr. There are a couple of ways to go about it:

Option 1

You can export your current keyboard layout to a file, change only the behavior of the right alt key (AltGr) and load it back to X, overriding the default layout:

  1. Run xkbcomp $DISPLAY current.xkb to export your current keyboard layout.

  2. Open the current.xkb file and locate the following snippet:

    key <RALT> {
        type= "ONE_LEVEL",
        symbols[Group1]= [ ISO_Level3_Shift ]
  3. Change it as follows:

    key <RALT> {
        type= "ONE_LEVEL",
        symbols[Group1]= [ ISO_Level3_Shift ],
        actions[Group1]= [ LatchMods(mods=AltGr) ]
  4. Save the file and run xkb current.xkb $DISPLAY to apply the new layout.


  1. The new layout is only good for the current X session. You'll probably want to reload it automatically after you log in. If you are using a window manager, just add xkb current.xkb $DISPLAY to your .xinitrc or .xprofile. If you are using a desktop environment, it might be a little trickier because DEs usually handle keyboard layouts their own way and they can override local configurations. Be sure to check their docs, or try Option 2 below.

  2. If you use multiple keyboard languages, you'll need to repeat the steps above for each exported xkb file and somehow load them when appropriate (e.g. using a shortcut for each language).

Option 2

You can create a new XKB option that enables the desired behavior for the AltGr key and then activate it along with a language layout:

  1. Create a file in /usr/share/X11/xkb/symbols named altgr with the following content:

    partial alphanumeric_keys
    xkb_symbols "latch" {
        key <RALT> {
            symbols = [ ISO_Level3_Shift ],
            actions = [ LatchMods(mods=AltGr) ]
  2. Open the evdev file in /usr/share/X11/xkb/rules and locate the line ! option = symbols. Add a new line after it and insert altgr:latch = +altgr(latch). It will look like the following:

    ! option  = symbols
      altgr:latch = +altgr(latch)

    +altgr(latch) means use the latch group from the altgr file located in /usr/share/X11/xkb/symbols.

Now you need to activate the new option. You can do one of the following:

  1. Run setxkbmap -layout us -variant altgr-intl -option altgr:latch to activate the new option, replacing us and altgr-intl with your language and variant. This will last for the current X session (useful for testing) and you may want to add it to .xinitrc or .xprofile so it will load automatically on login.

  2. If using systemd, run sudo localectl --no-convert set-x11-keymap us pc104 altgr-intl altgr:latch so your keyboard configuration in /etc/X11/xorg.conf.d is updated.

  3. If using a desktop environment, there might be a way to tell it to activate the option when loading the keyboard layout. I know GNOME uses dconf and you can set options for XKB in org.gnome.desktop.input-sources.xkb-options.


XKB files in /usr/share/X11/xkb aren't meant to be edited directly and might get overridden when performing system updates. The "right way" to change XKB configuration is way too complicated and I suggest you simply create a script that (re)applies the new option when needed.

  • Thank you very much for this answer (especially considering this question is quite old already)!
    – Raven
    May 28, 2021 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .