\ Bodhi Linux

Keyboard - Modify or Disable Caps Lock

Experience Level: Beginner

Prerequisites: Ability to use a command line.

Some people find the Caps Lock key rather annoying: it is too easy to hit it by mistake and it has limited usefulness. Fortunately, it is easy to disable this key or to modify its function in Bodhi Linux using the xmodmap command. In this guide I will cover terminal commands to disable and re-enable the Caps Lock key as well as commands to modify the function of Caps Lock. Then we shall see how to add these to Bodhi's Menu, as well as how to modify the Caps Lock key at startup.

Disable and Re-enable the Caps Lock Key

If you want to disable Caps Lock in Bodhi Linux, open the terminal and type the following command:

xmodmap -e "clear Lock"

If you want to re-enable Caps Lock in Bodhi, you need to execute the command below in the terminal:

xmodmap -e "add Lock = Caps_Lock"

Modify the Function of the Caps Lock Key

To modify the Caps Lock key so that it functions as another Shift key, run the following command in a terminal:

xmodmap -e "remove Lock = Caps_Lock" && xmodmap -e "add shift = Caps_Lock"

Afterwards, to re-enable the Caps Lock key:

xmodmap -e "remove shift = Caps_Lock" && xmodmap -e "add Lock = Caps_Lock"

As another example, let's modify the Caps Lock key so that it functions as a Backspace key. Use the command below in a terminal:

xmodmap -e "remove Lock = Caps_Lock"  && xmodmap -e "keycode 66 = BackSpace" 

And to re-enable the Caps Lock key:

xmodmap -e "keycode 66 = Caps_Lock" && xmodmap -e "add Lock = Caps_Lock"

The aforementioned commands may don't work using the latest Bodhi distribution (2.0 at the moment). I had success with those lines, they are redundant but they do the dirty job. This sequence should remap Caps_Lock to Control_L:

 #Re-enable it
 xmodmap -e "keycode 66 = Caps_Lock"
 xmodmap -e "add Lock = Caps_Lock"
 #Remove lock functionality
 xmodmap -e "remove Lock = Caps_Lock"
 #Say to xmodmap that Caps_Lock acts like a Control.
 xmodmap -e "add Control = Caps_Lock"
 xmodmap -e "keysym Caps_Lock = Control_L"

A Digression on Keycodes

As you have probably guessed by now, the Caps Lock key can be mapped onto any other key using the xmodmap command. For more information on the xmodmap command consult the man pages:

man xmodmap

To generate a list of what keycodes are mapped to which keys, use:

xmodmap -pke

As an example, the command above on my machine gives:

keycode  24 = q Q q Q

This means the Q key of my keyboard has keycode 24, and that pressing the Q without also pressing any other key yields the q character, while pressing Q and Shift simultaneously yields Q. Pressing Q and my keyboard's mode switch key simultaneously yields q, where on most keyboards the mode switch key is the Windows or Super key. And Pressing Q, Shift, and the Windows key yields the Q character.

Another useful tool to determine the keycode of a particular key on your keyboard is the xev command, the X event tester. As always, for more information see the man page:

man xev

Open a terminal and type xev, and a small window window labeled Event Tester will open up and your terminal will display information about all X Events. Move your mouse cursor over to the Event tester window and click on it to give it focus, and press any key for which you want information. Upon doing so, the terminal will output information on that key press. For example, pressing Q yields:

KeyPress event, serial 31, synthetic NO, window 0x1c00001,
root 0x102, subw 0x1c00002, time 10155761, (38,51), root:(38,76),
state 0x0, keycode 24 (keysym 0x71, q), same_screen YES,
XLookupString gives 1 bytes: (71) "q"
XmbLookupString gives 1 bytes: (71) "q"
XFilterEvent returns: False

We can see here the Q key has keycode 24.

Using either the xmodmap or the xev command, we can determine the keycode of any key on our keyboard; and then, using xmodmap, we can map the key to any character or Function key we wish.

Caps Lock Menu Items

Now back to the topic at hand. Instead of having to remember cryptic xmodmap commands, it would be good to create a Menu item for them. There are several ways to do this, but here I am going to directly create the .desktop file. For an alternative approach see the The Bodhi Guide to Enlightenment - Menu wiki, the subsection Customizing Bodhi's Menu: Adding an Application.

Here I am going to add two Menu items: the first to modify the Caps Lock key to function as another shift key, using the code above; and the second to restore the Caps Lock key.

First open Leafpad and copy and paste the code below into it:

[Desktop Entry]
Exec=(xmodmap -e "remove Lock = Caps_Lock" && xmodmap -e "add shift = Caps_Lock")

Now in Leafpad, save at the location ~/.local/share/applications with the name CapToShift.desktop.

Note: .local is a hidden folder in your home directory, and to see hidden folders in Leafpad's save dialog hit CTRL-H.

Now let's create a Menu item to restore the Caps Lock key. Again using Leafpad, copy and paste the code below into a new file:

[Desktop Entry]
Exec=(xmodmap -e "remove shift = Caps_Lock" && xmodmap -e "add Lock = Caps_Lock")

And save the file at the location ~/.local/share/applications with the name CapRestore.desktop.

Now both CapToShift and CapRestore will be in your Main Menu under Applications → System. To modify the Caps Lock key to function as any other key, simply modify the Exec statement in the .desktop files above to use the appropriate commands.

If you wish to change the icon in the Main Menu, you will need to modify the Icon statement in the .desktop files. Icons in Bodhi are stored at /usr/share/icons as well as /usr/share/pixmaps and possibly a few other locations. You can use any of these icons or if you prefer create or download one of your own. Note that you may need to specify the full path to your icon in the Icon statement in the .desktop file.

Caps Lock Modifications at Startup

Once we have created .desktop files, it is simple to add one to Enlightenment's startup programs.

For the CapToShift example from above, open Bodhi's menu and choose: Settings –> All –> Apps –> Startup Applications. In the Startup Applications dialog which opens up, click on the Applications tab and highlight CapToShift, click Add and then Apply and Close.

Now either log out and then log back in, or reboot: Caps Lock should now be another backspace key.

Alternate Method

Create a file named ~/.xmodmaprc with your xmodmap commands listed line by line.

# Example ./xmodmaprc

clear lock               # Remove all keysyms mapped to lock modifier
add shift = Caps_Lock    # Add Caps_Lock keysym to shift modifier

Then, if it does not already exist, create another file name ~/.xsessionrc. Add this to it:

# ./xsessionrc

xmodmap ~/.xmodmaprc

Modifications will be reflected after reboot.

Further Notes

  • This article is based upon a forum post of mine where I used a slightly different approach. I created a shell script and added the shell script to Enlightenment's startup programs. Interested readers can consult the forum post.
  • More advanced readers or cli junkies may wish to consider creating aliases for the xmodmap they use and add these to their .bashrc file.
  • An alternate way to modify the Caps Lock key at startup is to add the necessary commands to the .bashrc file. Note: I have not tested this yet, but in theory it should work.
  • Yet another untested way to modify the Caps Lock key at startup for more advanced readers is to create a .Xmodmap file and ensure it is loaded at startup. This approach is most useful if you wish to alter many or all keys at startup.
  • This wiki has been tested using Bodhi 1.0.0 and Bodhi 1.1.0 using a standard English keyboard. If you are using a non-standard or other-nationality/language keyboard and notice a discrepancy with the commands given above, or if you have any other difficulty following this tutorial, please contact me, post on the forums or edit this wiki with the relevant details. Thanks.

User Feedback

Did you find this article helpful?
Yes, right on the money!
Somewhat. Needs work.
Not really
Not at all.

If you would like to comment or make further suggestions, please leave a note on our Comments page (you will have to Create an Account if you haven't already).

original article by ylee

keyboard_-_modify_or_disable_caps_lock.txt · Last modified: 2012/11/07 11:56 (external edit) · [Old revisions]

© Copyright Bodhi Linux 2012. All Rights Reserved - Hosted by vaultnetworks