Posted: . At: 11:21 AM. This was 8 years ago. Post ID: 9416
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


How to toggle the caps lock key with the command line in Linux Mint.


  1. Disable the caps lock key in the command line
  2. Disable caps lock in the GUI

Disable the caps lock key in the command line

The Caps Lock key may be toggled using the command line. The xdotool utility will do this for you. Firstly, install the utility.

jason@jason-virtual-machine ~ $ sudo apt install xdotool

Then toggle the caps lock key with this command.

jason@jason-virtual-machine ~ $ xdotool key Caps_Lock

Run this command again to turn caps lock off.

On a Virtual Terminal, this will also work.

setleds -D +caps

This will turn caps back off.

setleds -D -caps

This line of code will turn off caps lock in Linux when used in the terminal.

python -c 'from ctypes import *; X11 = cdll.LoadLibrary("libX11.so.6"); display = X11.XOpenDisplay(None); X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(2), c_uint(0)); X11.XCloseDisplay(display)'

This is three ways to toggle caps lock with the command line. Are there any more? I will have to investigate this and see.

Disable caps lock in the GUI

This is how to do this on Linux Mint or Ubuntu with the MATE desktop.

Go to System -> Preferences -> Hardware -> Keyboard and click Layouts and the Options button and click Caps Lock behavior. This allows changing keyboard options. Disable caps lock in that dialog.

This works very well on the MATE desktop. This shows how flexible the Linux Mint MATE desktop really is.


7 thoughts on “How to toggle the caps lock key with the command line in Linux Mint.”

  1. Perfect, I was looking for this solution with x11vnc server. When you leave the session, if you forget caps lock on, then it remains always on, for next sessions.
    Previously, I had installed a virtual keyboard, which is also fine, but your solution is better and faster.
    thank you :thumb up:

    Reply
  2. thanks dude the last line of code was the one that actually worked for me but had to add python3 at the beginning instead.
    not sure whats going on with my system but made that line in to a terminal script command for convenience

    Reply
    • My caps lock LED light was ON, but it was typing lower case.
      I ran xdotool as in the post above. The LED did not change.
      But, when I typed, it was lower case. I hit the caps lock key,
      led went out, and I was still in lower case typing, and all
      was cool after THAT.

      Reply
  3. Thanks much for sharing this. My Linux Mint 18.3 on a Lenovo T520 has the Caps Lock turn on *every* time I use the computer. Although seems to be worse when docked and using a KVM switch, it still happens occasionally when using laptop all by itself!

    Reply
  4. This post helped me a lot!

    I have CapsLock disabled, but for some mysterious reason it becomes toggled once a month.
    Running command ‘xdotool key Caps_Lock’ is much better than rebooting.

    Thank you!

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.