Posted by Michał ‘mina86’ Nazarewicz on 11th of October 2009
Have you ever wondered why Caps Lock, a key you press twice a decade (once to turn it on and then to turn it off), is in such a lucrative position on the keyboard? And how about Ctrl? Compared to Caps Lock it seems like miles away. If you think about it old unix keyboards with those keys swapped seem to got it right.
I’ve gone one step further and recommend turning Caps Lock into Ctrl key altogether. In this article I will describe how to do that in various systems and platforms. But lets start with some propaganda.
First of all, if you don’t use Caps Lock at all why waste space on the keyboard? Honestly! Personally I don’t even remember when I used Caps Lock last time — have I ever used it at all? If you feel the same way you should definitely go for it! Caps Lock+s is way easier to press then Ctrl+s and that’s a key binding often used on various systems.
If, on the other hand, you do use Caps Lock you need to analyse how often — if rarely I still say go for it! Requirement to press Shift a little more is minor annoyance compared to benefits which came from not having to stretch your little finger so much.
But, if you use Caps Lock all the time, then still — go for it and stop SCREAMING on IRC and in mails so much! No, honestly — flame wars are not good for you health.
I’ve basically forced this settings on one of my colleagues at work (he asked me for help and I kept toggling Caps Lock when I wanted to press Ctrl so I’ve made the change) who was not pleased at first but then seemed to like it.
If you made a decision to give it a try you’ll probably wondering that swapping Caps Lock and left Ctrl is better idea then using both those key as Ctrl. But I say no!
Caps Lock is so rarely used that whenever it is it wasts space and I find some of the key shortcuts to be typed easier with lower left Ctrl (but that may be only a habit) — in particular all the Ctrl+Shift+whatever bindings.
Moreover, old habits die hard and so you’d make too many mistakes if you’d place Caps Lock where you’re used to have Ctrl.
Usually, with modifications like that an argument of other people’s computers comes in mind — what if I have to do something on some machine without those modifications?
This is a perfectly valid argument but you need to ask yourself how often do you work on computers you don’t own or have control over configuration of? In my case it’s a small fraction of a per cent so I decided not to bother.
Of course, even if you are going to spend significant amount of time on other people’s computers you can still consider the change — it’s up to you.
Lets start with widely used in *nix word X-Window system. First of all, if you are using KDE or Gnome you might try looking into keyboard’s configuration applets of those desktops — there may be an option to configure modifiers map.
Should you not find an option you’ll have to change some files by hand. As mentioned above I advocate using Caps Lock as another Ctrl and so examples will feature
ctrl:nocaps option — if you’d rather swap the two keys use
ctrl:swapcaps instead. You can of course specify several options if you have some already by separating them with colons.
Xkb, Debian & Debian-based (like Ubuntu)
If you are using Debian or Debian-based Linux distribution (such as Ubuntu) and you are lucky all you need to do is to edit
/etc/default/console-setup file. It has a line that says
First modify it to:
and then force dpkg to integrate your configuration by invoking as root:
I’ve been told it should work (ie. that’s what console-setup package is for) but if it does not for you (didn’t for me) just move to the next section.
XKb, Configuration file
If you’re not on Debian-based distribution or the above method failed you might try fidling with X11 configuration.
First of, check if your system contains
/etc/X11/xorg.conf.d directories (this is the case with Slackware starting with version 13.37). If it does, the former will most likely contain a file with “keyboard” or “layout” in its name such as
90-keyboard-layout.conf. If it does all you need to do is copy it to the latter directory:
cp -i /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf \ /etc/X11/xorg.conf.d/
Once the file is copied, either add or modify the “XkbOptions” option by adding “ctrl:nocaps”. For instance, the file could look something like this:
Section "InputClass" Identifier "keyboard-all" MatchIsKeyboard "on" MatchDevicePath "/dev/input/event*" Driver "evdev" Option "XkbLayout" "us" #Option "XkbVariant" "" Option "XkbOptions" "terminate:ctrl_alt_bksp,ctrl:nocaps" EndSection
If this does not work or the files are missing, you may need to edit X configuration file located at
/etc/X11/XF86Config on older systems. Like before, if there’s an InputDevice section for your keyboard it’s enough to add/modify the “XkbOptions” option.
It may happen that there is no InputDevice section for your keyboard — that’s actually all right. Newer versions of XOrg may use HAL to determine available input devices in which case you need to instruct it to pass proper options. First find proper policy file somewhere in
/etc/hal/policy directory (under Slackware it’s
10-keymap.fdi). Inside change
merge element with input.xkb.options key by adding
ctrl:nocaps to the value. For instance here’s my file:
<?xml version="1.0" encoding="ISO-8859-1"?> <deviceinfo version="0.2"> <device> <match key="info.capabilities" contains="input.keymap"> <append key="info.callouts.add" type="strlist">hal-setup-keymap</append> </match> <match key="info.capabilities" contains="input.keys"> <merge key="input.xkb.rules" type="string"></merge> <merge key="input.xkb.model" type="string">evdev</merge> <merge key="input.xkb.layout" type="string">pl,pl,pl</merge> <merge key="input.xkb.variant" type="string">,dvorak,dvp</merge> <merge key="input.xkb.options" type="string">ctrl:nocaps,terminate:ctrl_alt_bksp</merge> </match> </device> </deviceinfo>
If all of that fails or you don’t have super user privileges you may need to use xmodmap. Usually it’ll be enough to create a
.Xmodmap file in your home directory with the following content:
remove Lock = Caps_Lock add Control = Caps_Lock
And to further turn left Ctrl to Caps Lock:
remove Control = Control_L add Lock = Control_L
To test if the file works simply invoke
xmodmap ~/.Xmodmap. If you got your desired effect then everything should work next time you restart X session. If
~/.Xmodmap does not get applied automatically you should consult your distribution’s documentation — it’s possible you’ll need to edit (or even creat) an
~/.xinit file (you might take a look at mine if you want).
If you never use console or use it to merely log in and invoke
startx you may skip this section but otherwise read on. First of all, however, I must admit that even thought I’m reffering to "Unix Console" I’m not sure if what I’m going to write here is going to work for all kinds of *nix systems.
To avoid confusion I need to make it clear that console (or virtual terminal or vtt) is not what you get in graphical interface (
gnome-terminal, etc.). On some GNU/Linux distributions users may not even see it — a funky bootsplash can hide it pretty well. If you don’t know what it is just skip this section — you probably don’t need that knowledge.
Debian & Debian-based (like Ubuntu)
According to Moving the Ctrl Key under Debian and Debian based distributions it’s enough to add the following line to
s/keycode[[:space:]][[:space:]]*58[[:space:]][[:space:]]*=[[:space:]][[:space:]]*Caps_Lock/keycode 58 = Control/
and make it effective by invoking:
sudo invoke-rc.d console-screen.sh restart
If you also want to have Caps Lock under Ctrl add the following line as well:
s/keycode[[:space:]][[:space:]]*29[[:space:]][[:space:]]*=[[:space:]][[:space:]]*Control/keycode 29 = Caps_Lock/
If you are using an US layout you might give
emacs2 layouts a try. Personally I’ve never tried those but they may be what makes the trick for you.
To test them invoke
loadkeys emacs or
loadkeys emacs2 command in the console. If either of the two is what you want configure your system to use it by default.
Under Slackware you need to edit
/etc/rc.d/rc.keymap file. Under Gentoo try
/etc/conf.d/keymaps. On other systems — sorry, your on your own but it shouldn’t be hard.
If all of the above fails, you have a non-USB kayboard and you need a quick and dirty solution try
setkeycodes 0x3a 29 (plus
setkeycodes 0x1d 58 if you want to swap).
If it does not work try to verify the numbers. To do that run
showkey command in the console. Pressing Caps Lock and Ctrl will give you their keycodes (58 and 29). Then invoke
showkey -s. Now you’ll be given scancodes (0x3a and 0x1d). If the numbers were different change the
setkeycodes command accordingly.
If you have found command which works for you it’ll be enough to put that somewhere in start scripts. Under Slackware logical choice would be the end of
/etc/rc.d/rc.keymap file. Other systems usually have a “local” start script which one can edit — try
/etc/rc.local (you should refer to distribution’s documentation).
If the above method fails or you prefer a “cleaner” solution you will need to edit your keymap. First consult
loadkeys man page to find you where keymaps are saved on your systems (
/use/lib/kbd/keymaps are usual choices). Inside you’re find directories for various architectures in which there are directories for keyboard types and finally there are
.map.gz files describing keymap. For instance, I use
After you have located your keymap all you have to do is:
cd /path/to/keymap/directory # eg. cd /usr/share/kbd/keymaps/i386/qwerty gzip -d <kaymap.map.gz | \ sed -e 's/keycode[[:space:]][[:space:]]*58[[:space:]][[:space:]]*=[[:space:]][[:space:]]*Caps_Lock/keycode 58 = Control' \ -e 's/keycode[[:space:]][[:space:]]*29[[:space:]][[:space:]]*=[[:space:]][[:space:]]*Control/keycode 29 = Caps_Lock/' \ | gzip -9 >kaymap-my.map.gz
You can use a bit more descriptive suffix instead of
-my — for instance
-swapcaps. Also this will swap the Caps Lock and Ctrl key — if you’d rather use two Ctrls skip the second
If you can’t seem to find proper map file invoke
dumpkeys instead of
gzip -d <kaymap.map.gz in the above command.
After you’ve created your new keymap test it with
loadkeys keymap-my command. If that’s what you want instruct your system to use it permanently — refer to US layout section.
All of the above methods were tested on various Linuxes so I don’t know if they’ll work on other *nix systems. However, I found out that under NetBSD creating a
/usr/share/wscons/keymaps/pckbd.c2c file with a single
keysym Caps_Lock = Control_L entry and adding
mapfile /usr/share/wscons/keymaps/pckbd.c2c to
/etc/wscons.conf should do the trick.
In case you’d like to find out more about Unix and X applications mentioned try man pages:
Unfortunately, the world is not all Unix but even Microsoft Windows users can help their little finger.
Windows NT, Scancode Map
Under Windows NT an entry in the registry should suffice. Simply create or download certain .reg file, apply it by double clicking and finally restart the system for changes to take effect.
The files are caps-as-ctrl.reg:
REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
REGEDIT4 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00
Travis Krumsick created a tool called KeyTweak which may help you create your own Scancode Map entry. There’s also an archived Scan Code Mapper article at microsoft.com which describes how Scancode Map works in case you are interested.
where <path> represents the directory where you have placed Ctrl2Cap.
If you happen to use MacOS X and want to configure your Caps Lock key you shall go to Keyboard & Mouse panel in System Preferences. When there, select Keyboard tab and press Modifier Keys and make desired changes.
There’s also a uControl tool which lets you make the changes.
Using Caps Lock as another Ctrl key is not the only thing you can do. Colemak’s authors decided it’s better used as another Backspace. Personally I use Ctrl+H instead of Backspace so I prefer having Ctrl there.
I’ve heard Vim users like to use Caps Lock as another Escape but since Escape is the same as Ctrl+[ again maybe having another Control there is better?
With a little research and modifications you can, of course, use Caps Lock as anything you like. In my opinion, thought, what everyone should realise is that Caps Lock is useless and at the same time occupy an easy-to-reach position on the keyboard so why waste space?