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

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);
| improve this answer | |
  • Excellent, works like a charm, thanks! BTW what is the -s option? Didn't find documentation with my GNU cc, worked without it. – Ned64 Feb 28 at 19:06
  • -s strips the debug symbols, makes the (on-disk) binary smaller – mosvy Feb 28 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 Feb 28 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.