Score:0

How to remap CapsLock to a Gnome keyboard shortcut?

de flag
ARX

On Ubuntu 20.04, I want to switch to the workspace above by just pressing the CapsLock key. However, the following does not work:

gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up ['capslock']

Neither can I do it from the GUI, because in Settings, CapsLock is not recognized. But anyway, my need is to be able to do it from the command line.

How to, pls?

vanadium avatar
cn flag
In the keyboard layout options, you could make Capslock an additional Super key
ARX avatar
de flag
ARX
Thanks, but that would conflict with a different functionality I already have for the Super key.
Score:1
cn flag

You indeed cannot bind modifier keys to a command. However, the tool xcape can remap hitting and releasing a modifier key to a keyboard combination.

Thus,

xcape -e 'Caps_Lock=Super_L|Next'

would make you switch to the next workspace by hitting and releasing CapsLock, because Super+PgDn is a default existing keybinding to move to the next workspace.

uNFORTUNATELLY, THAT CHANGES THE cAPSLOCK sTATE EACH TIME.

To avoid that, one trick is to fisrt remap CapsLock to Hyper, which is not present on common keyboards using the xkb options. You can do this using Gnome Tweaks on the "Keyboard & Mouse" tab. Then, next command will do the trick:

xcape -e 'Hyper_L=Super_L|Next'
ARX avatar
de flag
ARX
Mapping CapsLock to Hyper_L is a great suggestion. Thank you very much. Since I needed to do all of it from a script, I ended up mapping with xmodmap: `xmodmap -e "keycode 66 = Hyper_L"`, and then using directly Hyper_L for changing the workspace: `gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up "['Hyper_L']"`. Works like a charm.
vanadium avatar
cn flag
If at some point you notice that the mapping disappears, you still can implement the mapping directly with the xkb options. May happen if you change keyboard, or if your computer resumes from sleep. I was not expecting that 'Hyper_L' alone in the gsettings command would work, so that is indeed nice
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.