I routinely disable Caps Lock and the respective modifier with a script, using xmodmap. That all works fine.

Sometimes, however, for some reason unknown, Caps Lock is active. Having no key bound to Caps_Lock and no key bound to toggle the Lock modifier, I cannot switch Caps Lock off unless I reset the keymap, press the key, then re-map it to my desired configuration.

So: How can I disable Caps Lock (currently active) without re-mapping keys and with no keys bound to do the job?

Perhaps a command line tool can set the state?

For anyone interested, here is how my script disables the accidental activation of Caps Lock by a key press (I never enable it intentionally):

# I never want to use Caps_Lock.  Make Caps_Lock another Control_L...
xmodmap -e "remove Lock = Caps_Lock" 2> /dev/null
xmodmap -e "keysym Caps_Lock = Control_L" 2> /dev/null
xmodmap -e "add Control = Control_L" 2> /dev/null

2 Answers 2


I don't know of any utility which does that (except maybe xdotool key Caps_Lock?), but in the meanwhile you can compile this little program with cc xkb_unlock.c -s -lX11 -o ./xkb_unlock (provided that you have installed a compiler and the libc & xorg development packages) and use it as simply ./xkb_unlock.


#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <err.h>
#include <stdlib.h>

int main(void){
        Display *dpy;
        if(!(dpy = XOpenDisplay(0)))
                errx(1, "cannot open display '%s'", XDisplayName(0));
        XkbLockModifiers(dpy, XkbUseCoreKbd, 0xff, 0);
        XSync(dpy, False);
  • Excellent, works like a charm, thanks! BTW what is the -s option? Didn't find documentation with my GNU cc, worked without it.
    – Ned64
    Commented Feb 28, 2020 at 19:06
  • -s strips the debug symbols, makes the (on-disk) binary smaller
    – user313992
    Commented Feb 28, 2020 at 19:10
  • Thanks. I normally use the strip command for that. Good to know, though. At less than 21k size it's not a big concern in this case, though. BTW feel free to upvote my question if it was clear :-)
    – Ned64
    Commented Feb 28, 2020 at 19:15
  • 1
    I cannot believe how much manpower has been wasted over the years because of this historic glitch of having this key in the firstplace (typewriters). We should vote it out of our computers. The few people still wanting to use that are for sure a tiny group against the people annoyed or unbothered.
    – U.V.
    Commented Jan 16, 2021 at 1:57
  • 1
    @Nadav That program doesn't disable the CapsLock key, but turns the CapsLock state off when there's no CapsLock key you can use for that. As requested by the question. (In fact, it will unlock all modifiers, not just LockMask, but I don't know of any AltsLock key ;-)). Neither setxkbmap nor xmodmap can do that; xdotool key Caps_Lock can do that, but it will toggle the state, not turn it off.
    – user313992
    Commented Jul 11, 2021 at 5:37

For many years, xmodmap -e 'clear Lock' worked well for disabling the effect of caps lock. The xkb_unlock.c code posted in another answer does a similar things. But sadly, on my modern Linux distribution this no longer works. You need to use setxkbmap, instead of xmodmap:

setxkbmap -option caps:none

works like a charm.

  • 2
    Your suggestion removes the possibility to toggle Caps Lock. The question was about switching off Caps Lock while it is active and there is no key mapped to toggle/switch it. So basically, switch Caps Lock on, run your command, now how do you get rid of it (switch it off)?
    – Ned64
    Commented Jul 15, 2021 at 14:51

You must log in to answer this question.

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