Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

In the past 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?

share|improve this question
add comment

7 Answers 7

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.

share|improve this answer
add comment

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".

share|improve this answer
    
After few minutes settings go back - and again Caps Lock have usual behaviour. –  Vitaly Zdanevich May 4 at 11:30
add comment
  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

share|improve this answer
add comment

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

share|improve this answer
1  
@JacobJohanEdwards Note to self, check whether xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' still works. –  Jacob Johan Edwards Sep 30 '12 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. –  ragu.pattabi Mar 14 '13 at 15:47
4  
These settings don't exist anymore in 13.10. Install gnome-tweak-tool, there you will have similar settings under "Typing". –  pcworld Dec 23 '13 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. –  Andrew Wagner May 5 at 12:11
add comment

To remap the useless caps_lock into a basic shift, do

xmodmap -e "keycode 66 = Shift_L"
share|improve this answer
    
This does not persist after restart. –  Czarek Tomczak Oct 16 '13 at 9:41
    
To make it persist after restart do: Ubuntu Dash Home > Startup Applications > Add > Type the command above. –  Czarek Tomczak Oct 16 '13 at 9:50
add comment

This is basically a modification of the answer provided at http://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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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