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.
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.
Edit /etc/default/keyboard
and add custom:super_esc
to the XKBOPTIONS
variable (comma-separated).
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.
@bendavis78 That's brilliant!
Any chance to have a similar behavior with an ordinary key? I would like to have the J key to emit a J when pressed, and to act as a Shift when held down. Would it be possible?