3

I have found a lot of ways to map Caps Lock to Left Control. For example: editing /etc/default/keyboard and adding "ctrl:nocaps" to the XKBOPTIONS

But I can't find anywhere how to map to Right Control, I need it to be the right because I am trying to do something after that and being the right is necessary for the next step

How can I map Caps Lock to Right Control?

1

Use

xev

And press the key Right Control. You will get an event like this:

KeyPress event, serial 36, synthetic NO, window 0x4200001,
root 0x266, subw 0x0, time 253995826, (1344,552), root:(1410,604),
state 0x10, keycode 105 (keysym 0xffe4, Control_R), same_screen YES,
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False

Remember the keycode, in my case 105.

Create a script, for example /home/user/xmodmap.sh with the following:

#!/bin/bash
xmodmap -e "keycode 105 = Caps_Lock"

Now give permissions to the script with:

sudo chmod 755 /home/user/xmodmap.sh

And add it to be run when your Ubuntu starts going to System -> Preferences -> Startup Applications and creating a new entry with the command:

/bin/bash -c "sleep 5 && /home/user/xmodmap.sh"
  • Why the "sleep 5"? – Damaru Jul 7 '15 at 11:31
  • It is not working by the way. I have tried executing xmodmap with a file as argument whose content is: remove Lock = Caps_Lock remove Control = Control_R keysym Caps_Lock = Control_R add Control = Control_R And it works if I execute it in a term, but it doesn't if I run it automatically at boot (neither with a sleep 5 before) – Damaru Jul 7 '15 at 12:18
  • The reason for the sleep is better explained here: askubuntu.com/questions/644657/… – Katu Jul 7 '15 at 20:44
  • Have you tried a script like the example I gave? It works for me in Ubuntu 12.04, 14.04 and 15.04... You might want to sleep for longer. Are you using Unity? – Katu Jul 7 '15 at 20:46
  • I have tried it and it doesn't work for me. It doesn't even work if I execute it in a term after booting. My machine is running Xubuntu 14.04 (XFCE + Ubuntu). – Damaru Jul 8 '15 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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