How do you remap a key to the Caps Lock key in Xubuntu?
then find the line that starts with XKBOPTIONS , and add ctrl:nocaps to make Caps Lock an additional Control key or ctrl:swapcaps to swap Caps Lock and Control.
For example, mine looks like
XKBOPTIONS="lv3:ralt_alt,compose:menu,ctrl:nocaps"
sudo dpkg-reconfigure keyboard-configuration
The reason this way is better is that it will take effect on the virtual consoles (e.g. Ctrl + Alt + F1 ) as well as in the graphical desktop.
XkbOptions is named for a setting in X. The capability is provided by the console-setup package, which seems to have been in Ubuntu since at least Lucid, and probably earlier.
Xubuntu → Settings Manager → Session and Startup
Then in the Sessions and Startup configurator go
Application Autostart (tab at the top) → Add (bottom button)
Now on the Add Application screen
- Name: Control and CapsLk swap
- Description: Swap the two keys
- Command: /usr/bin/setxkbmap -option «ctrl:swapcaps»
To remap Caps Lock to Control go:
Xubuntu → Settings Manager → Session and Startup
Then in the Sessions and Startup configurator go
Application Autostart (tab at the top) → Add (bottom button)
Now on the Add Application screen
Name: Remap CapsLk to Ctrl Description: Remap the CapsLk key to Control Command: /usr/bin/setxkbmap -option "ctrl:nocaps"
Remaping Ctrl+Capslock and Alt+Capslock on Ubuntu
This disables Capslock and maps Shift+Capslock to Capslock, but what I want is Ctrl+Capslock instead of Shift+Capslock. I have no idea how to map Alt+Capslock to the Escape key. I want to clarify that I don’t need an answer to use Xmodmap, any method will be fine.
+1 All my life being frustrated how easy it is to press accidentally CAPS while typing fast only to a sentence later discover that you have to retype everything anew.
1 Answer 1
Xmodmap cannot do what you’re asking for, but it can bring you close.
The basic syntax for modifying the behavior of a key is
xmodmap -e "keycode KEYCODE = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4" xmodmap -e "keysym KEYSYMBOL = KEYSYMBOL1 KEYSYMBOL1 KEYSYMBOL3 KEYSYMBOL4"
- KEYSYMBOL2 gets triggered when pressing the key while pressing Shift .
- KEYSYMBOL3 gets triggered when pressing the key while pressing ModeSwitch .
- KEYSYMBOL4 gets triggered when pressing the key while pressing Shift + ModeSwitch .
- KEYSYMBOL1 gets triggered when pressing the key with none of the above.
- ModeSwitch is AltGr by default (only works on some keyboard layouts).
We can’t set Ctrl or Alt to be the ModeSwitch key, since no key can serve as two different modifiers.
However, we can turn CapsLock into the ModeSwitch key:
xmodmap -e "keysym Caps_Lock = Mode_switch Mode_switch"
To remap CapsLock + Ctrl to the CapsLock key, execute the following commands.
xmodmap -e "keysym Control_L = Control_L Control_L Caps_Lock" xmodmap -e "keysym Control_R = Control_R Control_R Caps_Lock"
Note the CapsLock is the modifier key here, so you have to press this key first.
We can’t remap CapsLock + Alt or CapsLock + Super to Escape in the same manner, since Alt and Super serve different functions when pressed alone and when used as modifier keys.
Every other key will work fine. Examples:
- For CapsLock + ` (standard US layout), use
xmodmap -e "keysym grave = grave asciitilde Escape"
xmodmap -e "keysym space = KP_Space KP_Space Escape"
- To make the remappings permanent, create/edit the file .gnomerc in your home folder and save the corresponding commands in it.
- To undo all remappings, simply execute
Map Caps Lock to Control in Linux Mint
I am running the latest version of Linux Mint with Cinnamon. I’m trying to map Caps Lock to Ctrl , but I cannot figure out how to do it. All web searches I’ve done have led me to older versions of Linux Mint (there is no keyboard layout option in my settings). How can I do this?
Can you update your question to indicate exactly what the latest version is? This question could be here for years.
As a guide line . the ‘current’ Linux Mint release is #18 (~2016), so quoting «the latest» of almost anything in computing is going to rapidly fade the ‘factual‘ colour. (Including this one.)
8 Answers 8
You can accomplish this with xmodmap . Add the following to ~/.xmodmap :
remove Lock = Caps_Lock keysym Caps_Lock = Control_L add Control = Control_L
and run the command xmodmap ~/.xmodmap . You can put this command in whatever startup files are processed by your WM or DE. This will only work in X but it will work regardless of what graphical environment you use.
Using xmodmap and the solution in your startup file sucks a bit, there is no answer for the question Zamicol raised and if you’d put it in your .profile it will only be applied if you have your terminal opened. The solution by @don_crissti using gnome-tweak-tool is nicer; it allows the setting to be active when your WM starts
I found it. It was moved to the regional preferences section:
Go to settings > regional preferences > keyboard layouts > settings and expand the caps lock section.
In Linux Mint 17.1 you can get to it via;
System Settings > Hardware > Keyboard > Keyboard Layouts > Options > Caps Lock key behavior
No need to use the obsolete xmodmap as there’s already an xkb option — namely ctrl:nocaps e.g. in terminal:
setxkbmap -option ctrl:nocaps
With gnome 3 you can either use dconf-editor and add ctrl:nocaps to your xkb-options under org > gnome > desktop > input sources:
or simply enable Caps Lock as Ctrl in gnome-tweak-tool under Typing > Ctrl key position:
Perhaps worth mentioning man keyboard and also the permanent config location in /etc/default/keyboard
For LinuxMint 17 with KDE it was: System Settings > Input Devices > Keyboard > Advanced > Ctrl key position
I realize that this already has an accepted answer, but here is the One True Way to change Caps Lock to ctrl . This works on all versions of Linux, all distros, for the entire system (console, X, whatever). It sets the mapping in the kernel where it should be.
(echo $(dumpkeys |grep -i keymaps); echo keycode 58 = Control) | loadkeys -
Add this to a start up script (e.g., /etc/rc.local , or create your own).
On Debian (and derivatives) dumpkeys/loadkeys is part of the kbd package, if for some reason it’s not already installed.
How do I remap the caps lock key?
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?
11 Answers 11
From howtogeek.com which has a good answer for any OS.
For Linux (including Ubuntu):
Where 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.
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
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á.
In Ubuntu 11.10 — 13.04
- Open the Keyboard Layout application and click the «Options» button.
- A list of rebinding options will apear. Select «Caps Lock key behavior».
- Select your preferred Caps Lock repurposing option.
@JacobJohanEdwards Note to self, check whether xmodmap -e ‘clear Lock’ -e ‘keycode 0x42 = Escape’ still works.
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.
These settings don’t exist anymore in 13.10. Install gnome-tweak-tool , there you will have similar settings under «Typing».
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.
You can disable it by going to keyboard->Layouts->options->caps lock behavior and choose «disable caps lock» .
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 .
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.
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/tty6, or Ctrl-Alt-F5).
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
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
To remap the useless caps_lock into a basic shift, do
xmodmap -e "keycode 66 = Shift_L"
To make it persist after restart do: Ubuntu Dash Home > Startup Applications > Add > Type the command above.
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.
The following method uses the combination of Compiz to launch an application when a key-press is made.
- change the behaviour of the Caps Lock key to mimic another key.
- 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:
keycode 66 = cent clear Lock add Control = cent
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.
Configure Compiz
Start the CompizConfig Settings Manager
In the general section, ensure «Commands» is enabled and configure a command as shown:
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.
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».
- 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)
Also, for more help on xmodmap: