81

In the the past I used to use xmodmap to prevent the Caps Lock button from working, and then tell Launchy to handle the key press instead. I can't seem to do this anymore.

What is the best way to disable Caps Lock's normal behavior, and make it do something else?

1

11 Answers 11

97

From howtogeek.com which has a good answer for any OS.

For Linux (including Ubuntu):

setxkbmap -option <OPTION>

Where <OPTION> can be for example of:

  • caps:none – Disables Caps Lock.
  • caps:super – Caps Lock becomes an additional Super (aka Win key).
  • caps:ctrl_modifier – Caps Lock becomes an additional Ctrl.
  • caps:numlock – Caps Lock becomes an additional Num Lock.
  • caps:escape – Caps Lock becomes an additional Escape.
  • caps:backspace – Caps Lock becomes an additional Backspace.
  • caps:swapescape – Caps Lock becomes Escape, and Escape becomes Caps Lock

Note: Xmodmap is deprecated in favor of setxkbmap.

10
  • 4
    love you man, thanks , it works for ubutnu 14.10 Dec 26, 2015 at 0:56
  • 6
    nice and simple, works in 16.04
    – chepyle
    Jun 7, 2016 at 1:23
  • 8
    To restore any setxkbmap changes (i.e. if you need your Caps key back to its original location) one only needs to run this: setxkbmap -option
    – landroni
    Jul 6, 2016 at 8:50
  • 1
    If you remaped the Capslock key to backspace and now you wonder why it won't delete words if you keep it pressed, it's because you need to use an extra command. After setxkbmap -option caps:backspace enter xset r 66 and voilá.
    – Gabriel
    Jan 7, 2017 at 2:29
  • what if I want to remap right alt to escape? alt:escape doesn't work Apr 22, 2017 at 10:42
23

In Ubuntu 11.10 - 13.04

  1. Open the Keyboard Layout application and click the "Options" button.
  2. A list of rebinding options will apear. Select "Caps Lock key behavior".
  3. Select your preferred Caps Lock repurposing option.

Screenshot of available options

5
  • 1
    @JacobJohanEdwards Note to self, check whether xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' still works.
    – Jjed
    Sep 30, 2012 at 15:37
  • For vim users, 'Practical Vim' recommends to map the caps lock to ctrl at the system level. Keyboard Layout > Options > Ctrl Key Position > Caps Lock as Ctrl does the trick.
    – rpattabi
    Mar 14, 2013 at 15:47
  • 13
    These settings don't exist anymore in 13.10. Install gnome-tweak-tool, there you will have similar settings under "Typing".
    – pcworld
    Dec 23, 2013 at 22:08
  • This is not working for me in Ubuntu 12.10. Messing with those settings in the gnome-control center don't seem to have any effect. May 5, 2014 at 12:11
  • 4
    Why did they remove these options from 14.04? Dec 31, 2015 at 20:46
19

You can disable it by going to keyboard->Layouts->options->caps lock behavior and choose "disable caps lock" .


Edit:

I don't know why it seems inconvenient with another Keyboard keys.

But Launchy works fine with me after trying it with CTRL+Super+Space.

enter image description here

And you need to white-list launchy to the tray icons. See How do I access and enable more icons to be in the system tray?. Also you need to add it to the Start Up applications, as it won't work when it is not opened.


After all, As an alternative for Launcy, try Synapse for its best integration with gnome and unity.

1
  • This option does not seem to be available to me on Ubuntu 15.04.
    – MichielB
    Nov 19, 2015 at 13:13
17

This is basically a modification of the answer provided at https://askubuntu.com/a/223674/22073.

You can also modify the behavior of Caps Lock using an XKBOption. These changes are even propogated to the virtual consoles (/dev/tty[1-6], or Ctrl-Alt-F[1-6]).

For instance, to disable Caps Lock, you would have the following in /etc/default/keyboard:

# Check /usr/share/doc/keyboard-configuration/README.Debian for
# documentation on what to do after having modified this file.

# The following variables describe your keyboard and can have the same
# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
# in /etc/X11/xorg.conf.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="caps:none"

# If you don't want to use the XKB layout on the console, you can
# specify an alternative keymap.  Make sure it will be accessible
# before /usr is mounted.
# KMAP=/etc/console-setup/defkeymap.kmap.gz

Then you would run:

sudo dpkg-reconfigure keyboard-configuration

For a full list of the customizations of XKBOPTIONS, take a look at /usr/share/X11/xkb/rules/base.lst. Here's the full list from my Ubuntu 13.10 machine: http://sprunge.us/cUZO

Even more information can be found on the ArchLinux wiki: https://wiki.archlinux.org/index.php/Keyboard_Configuration_in_Xorg

2
  • Perfect, I'm using XKBOPTIONS="ctrl:swapcaps" to swap the Left Ctrl with Caps.
    – Márcio
    Jul 25, 2017 at 1:22
  • It works on 16.04 in X and the virtual consoles.
    – jfs
    Aug 24, 2017 at 16:18
12

To remap the useless caps_lock into a basic shift, do

xmodmap -e "keycode 66 = Shift_L"
3
  • This does not persist after restart. Oct 16, 2013 at 9:41
  • 4
    To make it persist after restart do: Ubuntu Dash Home > Startup Applications > Add > Type the command above. Oct 16, 2013 at 9:50
  • 3
    I would suggest doing xmodmap -e "keycode 66 = Shift_L Caps_Lock" instead so that you can still access the normal caps lock using key combination Shift+Caps lock if needed. For other purposes, the caps lock key behaves as additional left shift. Jun 4, 2021 at 7:54
7
+25

The following method uses the combination of Compiz to launch an application when a key-press is made.

In summary -

  1. change the behaviour of the Caps Lock key to mimic another key.
  2. Configure compiz to listen for the newly mimic'd key and run a custom script.

Change the caps lock key

Too change the behaviour of the Caps Lock Key, you can use xmodmap as follows:

  • create a file e.g. "capslock"
  • copy and paste the following into the file
keycode 66 = cent
clear Lock
add Control = cent
  • now run xmodmap to recognise your change:

xmodmap capslock

To run permanently add this command to the startup applications.

Pressing Caps Lock now just mimics pressing a "cent" key - note this is not a key that actually exists on my keyboard.

You can get a list of KeySym names from here.

Configure Compiz

Start the CompizConfig Settings Manager

In the general section, ensure "Commands" is enabled and configure a command as shown:

enter image description here

N.B. enable the key binding and use "grab key combination" to recognise your "cent" key. You cannot get compiz to recognise the cap lock key itself unfortunately.

enter image description here

Obviously - change "firefox" for whatever command you use to start "launchy"

Now when you hit the Caps Lock key, compiz will recognise the mapped "cent" key and run the command - in this case firefox - in your case "launchy".

1
  • After few minutes settings go back - and again Caps Lock have usual behaviour. May 4, 2014 at 11:30
5
  1. Use the xev command. When you hit enter, xev will launch. xev takes all of your input and poops info about the key into the command line. I recommend bringing your mouse over the exit key of the xev window, hitting caps lock (or whatever key you want to find out about), and immediately exiting xev. The relevant lines on my system, for caps lock look something like:

    KeyPress event, serial 36, synthetic NO, window 0x4400001,
        root 0x27a, subw 0x0, time 19164277, (16,-9), root:(1156,46),
        state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
        XLookupString gives 0 bytes: 
        XmbLookupString gives 0 bytes: 
        XFilterEvent returns: False
    
    KeyRelease event, serial 36, synthetic NO, window 0x4400001,
        root 0x27a, subw 0x0, time 19164397, (16,-9), root:(1156,46),
        state 0x2, keycode 66 (keysym 0xffe5, Caps_Lock), same_screen YES,
        XLookupString gives 0 bytes: 
        XFilterEvent returns: False
    

    Notice keycode (66) and keysym (0xffe5).

    You could also, now, get data for another key -- one you don't really use, and which, in the context you want to use the caps lock button in, doesn't do anything. So, if you want caps lock to activate the Unity searchbox (like super usually does), maybe use `, for example. On my machine:

    keycode 49 (keysym 0x60, grave)
    
  2. Bind the new key's function to the Caps Lock button, using xmodmap. I'm pretty sure you want to use a command like:

    xmodmap -e "keycode 66=0x60"
    

    Now, if you hit the physical caps lock button in a text box, the grave character (`) will appear. But if you map a shortcut key to it, it will do something else. If you want to be able to use it in a text box, perhaps replace caps lock with left shift, or f10, or something else that doesn't seem like it will interfere with the command you want to use.

  3. Test it to make sure the command I gave you works the way you want it to.

  4. Go to startup applications, and add that command to your startup applications. This way, the key will switch properly every time you start up.

  5. Dance.

(shout out to theprise) Change Keybindings (hardware to software)

Also, for more help on xmodmap:

http://www.xfree86.org/4.2.0/xmodmap.1.html

http://www.in-ulm.de/~mascheck/X11/xmodmap.html

0
5

Ubuntu 16.04

setxkbmap -option <OPTION> from Wernight's answer seemed to work immediately for me.

However it would go away on reboot. To address this I added to my startup applications

  1. Search for and run Startup Applications >> Click Add
  2. Put in /usr/bin/setxkbmap -option <OPTION> as the command (Note: the full path is important)

Replace <OPTION> with something like caps:escape (I use it for vi)

Background

I just upgraded from 15.10 to 16.04 and whatever I used to map this before stopped working.

3

while of course the xmodmap option would work I wanted to find an option that uses the GUI. This is available for me (using Ubuntu 15.10):

  • install gnome-tweak-tool
  • go to 'type'
  • under 'Behaviour of Caps Lock key' choose 'Caps lock is disabled'
2

The option that I found the best for me (in any X compatible wm/de) is adding

Option "XkbOptions" "caps:swapescape"

inside the

Section "InputClass"
    Identifier "system-keyboard"
    MatchIsKeyboard "on"
    Option "XkbLayout" "US"
    Option "XkbOptions" "caps:swapescape" # << is what you want
EndSection

block in /etc/X11/xorg.conf.d/00-keyboard.conf (create if necessary).

0

The most robust solution is to buy a keyboard that lets you remap keys in firmware, i.e. a professional, programmable keyboard.

These usually cost around 200 bucks and also have high grade mechanical keyswitches. They are expensive, but they are the only way to avoid having to fight with this at every new machine you sit down at, and each time the developers make breaking changes to OS infrastructure as fundamental as the keyboard map.

1
  • 2
    This does not help with a laptop.
    – wallyk
    Feb 21, 2015 at 20:14

You must log in to answer this question.

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