Linux.com

Home Learn Linux Linux Tutorials How to Kill the Caps Lock on your Linux Desktop

How to Kill the Caps Lock on your Linux Desktop

caps lock key removed from a keyboard

Didn't there used to be a straightforward, GUI-powered way to disable the Caps Lock key on one's keyboard? I remember it as being one of the first modifications I did as a Linux newbie that actually altered the way a piece of equipment performed (boy, was I proud!). But some time around Ubuntu 11.04 (yes, during the Unity Revolution) that function seems to have vanished. I still use the machinery of Ubuntu, but with the less restrictive Xubuntu as a desktop.

I really liked being free of the intrusive Caps Lock, since I'm not a very good typist; I look down at the keys a lot, and if I've hit the lock by mistake it can be half a line or more before I notice. Anyway, with Disable suddenly unavailable I did some searching and found that the function of the Caps Lock key could be replaced by adding a script to xmodmap.

Now my Linux smarts had increased some by then, but they weren't yet up to the do-it-yourself script level, so I did some more searching to find a ready-made script. The first script I found was to change the function of the key to a Shift only. It was simple; in Leafpad (or Gedit, for that matter), make a little file:

!
! Swap Caps_Lock and Shift_L
!
remove Lock = Caps_Lock
keysym Caps_Lock = Shift_L

Save it as a hidden file in your /home folder and give it a name that defines it as a runnable script: it could be .capless, .nocaps, .freeatlast, even .name, as long as that . in front of it is present. Then, whenever you want to assert your independence from that old fAMILIAR ENDLESS LINE of capital letters, just run:

$ xmodmap /home/yourname/.capless

in a terminal or, for fellow Xubuntians, set it up once and for all in your Application Autostart section.

That was all I needed, at least for a while, but when I started using a new low-profile keyboard I occAsionally would notice strAnge results. The caps didn't stay locked, but the overlap of my finger on lock key and letter key becAme an intermittent problem. (Well, maybe not that bad.)

I figured one good script deserved another, so I began to look into just how that sort of keysym changing really works under the hood. I checked out the man page for xmodmap and found I could access the entire keysym list by entering:

$ xmodmap -pk

That lists the keysyms in hexadecimal; at 7 keysyms per keycode and 255 keycodes, be prepared to scroll if you're looking for something special. I lucked out: right up at the top is 0x0000, for No symbol – Caps Lock doesn't do anything. I realized I had found the way those old-time keyboard-altering GUIs worked! On the spot I did my new Caps Lock-disabling script:

!
! Set Caps_Lock to no symbol
!
remove Lock = Caps_Lock
keysym Caps_Lock = 0x0000

and saved it as .killer in the Application Autostart part of the Settings Manager.

On a different machine where I run Lubuntu, it isn't quite as easy to set it up for automatic startup. Once you have the script written and saved, open

$ /etc/xdg/lxsession/LXDE

and open the autostart text. At the bottom, add the line

@.killer enable

Log out, log in again, and you will be caps-free for all your subsequent logins.

But if you're lazy like me, you can just do the script and put in the Run Program line the full:

$ xmodmap /home/emery/.killer

After a while it gets used to seeing that, and autocompletes.

 

Comments

Subscribe to Comments Feed
  • Paul Gorman Said:

    Another way to do this is setting these preferences in your ~/.xsession file. For example, I like to have my caps lock send Control, so I have this in my ~/.xsession: setxkbmap -option ctrl:swapcaps & setxkbmap -option ctrl:nocaps & Using ~/.xsession has the advantage that it's independent of whatever desktop environment you use, and will be run whenever you log in through a graphical display manager like gmd, xdm, or lightdm.

  • Mat Said:

    When I tried to run it I got this error. $ xmodmap /home/xxx/.capskill xmodmap: /home/xxx/.capskill:4: bad remove modifier name 'lock=caps_lock', not allowed xmodmap: /home/xxx/.capskill:5: bad keysym target key symbol 'Caps_Lock=0x0000' xmodmap: 2 errors encountered, aborting. This was the script: ! !Set Caps_Lock to no symbol ! remove Lock=Caps_Lock keysym Caps_Lock=0x0000

  • Lewis Said:

    Add a space on both sides of the "=", on both lines. "remove lock = Caps_Lock" and "keysym Caps_Lock = 0x0000". Then it should work for you.

  • Sam Said:

    Try setxkbmap, it's a lot easier, and lets you use options to do the same. I use dvorak(Obviously) and have my capslock as backspace, and use both shifts to do backspace. setxkbmap -model pc104 -layout "us(dvorak)" -option caps:backspace -option shift:both_capslock

  • Cow Said:

    In KDE go to SYSTEM SETTINGS > (HARDWARE) INPUT DEVICES, then select the ADVANCED tab in the KEYBOARD settings, select BEHAVIOUR FOR CAPS LOCK KEY then select the apropriate behavior, for example CAPS LOCK DEACTIVATED

  • ChiefH Said:

    A whole lot easier way is to click on "System Settings", then "Keyboard Layout" and in the lower right hand corner click on "Options". Next click on "Caps Lock Key Behavior" go to the choice "Caps Lock is Disabled". This works for me in Ubuntu 12.04LTS

  • David Klann Said:

    This has disappeared again with GNOME 3.10. With this version of GNOME you can disable the Caps Lock key (or re-assign it to be an additional Control key) using the GNOME Tweak Tool. Some distros call this package something like "advanced settings". Select the "Typing" tab and set your preferences accordingly.

  • Darrin Said:

    Really? Wow. This is a perfect example of how a tool (such as the caps-lock key) can be really useful to one but can be a complete hindrance to another. From the prospective of someone who is a fast typist, who does not look down at the keyboard a whole lot, the caps-lock key is a wonderful tool for when you are typing things in all CAPS or if you have a long acronym to type. I don't use it all that often, but when I do, I sure appreciate that it's there. (P.S. - I'm also really thankful that I took a typing class years ago in high school because it's proven to be the most useful skill that I probably ever learned in those days and is something that I use almost daily, both professionally and personally.) I'm also really appreciative of the fact that Linux is so incredibly customizable so that a user can curtail his/her computing environment exactly to his/her liking, as you have done by disabling the caps-lock key. Kudos to you!

  • hwalther Said:

    Hi, on my system cAPS-lOCK always worked. Any software effort FAILED. I use Ubuntu 14.04 along with LXDE and now installed a hardware program called DCLWP (Disable Caps Lock With Paper). This works with Mac OS 1 to 11, Microsoft Windows V.1.0 to 11, and any kind of Linux.


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board