Skip to content

Instantly share code, notes, and snippets.

@purpleidea
Forked from bendavis78/capslock_super_esc.md
Created November 18, 2018 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save purpleidea/c4d84d46def2d780d85e8c2d8a9d63fb to your computer and use it in GitHub Desktop.
Save purpleidea/c4d84d46def2d780d85e8c2d8a9d63fb to your computer and use it in GitHub Desktop.
Mapping Caps Lock to simultaneous Esc and Super (Mod4)

Mapping Caps Lock to simultaneous Esc and Super (Mod4)

The CAPS key can be mapped to an escape key when pressed once, and a super (mod4) key when used in combination with other keys.

Create the file /usr/share/X11/xkb/symbols/custom_opts with the following:

// Make Caps an additional Escape
hidden partial modifier_keys
xkb_symbols "super_esc" {
    key <CAPS> { [ Escape ] };
    modifier_map Mod4 { <CAPS> };
};

Edit /usr/share/X11/xkb/rules/evdev and add a new line in the ! option = symbols section:

  custom:super_esc = +custom_opts(super_esc)

Edit /usr/share/X11/xkb/rules/evdev.lst and add a new line the ! option section:

  custom:super_esc  Make Caps Lock an additional ESC and Mod4

Restart your X session and apply the setting using your DE's keyboard layout options.

Updating the keyboard layout option

Gnome

Open dconf-editor, and navigate to org.gnome.desktop.input-sources. Add 'custom:super_esc' to the xkb-options list. For example, if you have no other options set, just use ['custom:super_esc']. If you have other options set, separate using commas like so: ['compose:ralt', 'custom:super_esc'].

You can also use the gsettings command to do this via commandline.

XFCE

Edit /etc/default/keyboard and add custom:super_esc to the XKBOPTIONS variable (comma-separated).

Other options

Most laptops have the alt key really close to the windows key, which can result in accidental keypresses. I like to use the altwin:alt_win xkb option (Alt is mapped to Win and the usual Alt) to make both keys work as alt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment