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.
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"
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"
#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"
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:
To generate a list of what keycodes are mapped to which keys, use:
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:
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.
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] Hidden=false Exec=(xmodmap -e "remove Lock = Caps_Lock" && xmodmap -e "add shift = Caps_Lock") Type=Application NoDisplay=false Version=1.0 StartupNotify=false Terminal=false Name=CapToShift Name[en_US]=CapToShift Categories=System; Icon=applications-system.png
Now in Leafpad, save at the location
~/.local/share/applications with the name
.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] Hidden=false Exec=(xmodmap -e "remove shift = Caps_Lock" && xmodmap -e "add Lock = Caps_Lock") Type=Application NoDisplay=false Version=1.0 StartupNotify=false Terminal=false Name=CapRestore Name[en_US]=CapRestore Categories=System; Icon=applications-system.png
And save the file at the location
~/.local/share/applications with the name
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
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.
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.
.bashrcfile. Note: I have not tested this yet, but in theory it should work.
.Xmodmapfile and ensure it is loaded at startup. This approach is most useful if you wish to alter many or all keys at startup.
original article by ylee