3

Just read this seriously obsessive post about customising keyboards and while I'm not going to do everything there, there are a couple of ideas I'd like to nick. In particular he has set up the Caps Lock key so that:

  • when pressed and released alone, it is mapped to Esc
  • when pressed and held, and a second key is pressed, it is mapped to Ctrl

As he says, this is great for vim users. Is that possible in Ubuntu?

He also does something similar with the right and left Shift keys. When pressed alone they map to ( and ) but if another key is pressed they act as you expect Shift to work.

4

I found an answer on unix.se at least to the Caps Lock/Ctrl/Esc part.

First remap Caps Lock to an extra Control by putting the following in ~/.profile

if [ $DISPLAY ]
then
  # Add the 3 lines below to Convert caps-lock into Control
  xmodmap -e 'remove Lock = Caps_Lock'
  xmodmap -e 'keysym Caps_Lock = Control_L'
  xmodmap -e 'add Control = Control_L'

  # and xcape is in Startup Applications
fi

Then go get xcape - you'll need to install the dependencies (see the README) and do make and sudo make install. And then it does what the README says:

xcape runs as a daemon and intercepts the Control key. If the Control key is pressed and released on its own, it will generate an Escape key event.

I'm using it now and it's very nice :)

I guess a modified version could do the shift/parentheses thing as well.

| improve this answer | |
2

On Ubuntu 16.04

1st Option

Caps_Lock as Ctrl

  • open the file /etc/default/keyboard, and change XKBOPTIONS="" to:

    XKBOPTIONS="caps:ctrl_modifier"
    

Caps_Lock as Esc

  • install xcape with

    sudo apt install xcape
    
  • create .xsessionrc at the home directory (or edit if it already exist)

  • add the following line to ~/.xsessionrc

    #!/bin/bash
    
    /usr/bin/xcape -e 'Caps_Lock=Escape'
    

Note

  • you need to logout then login.
  • for a full list of all the options that you can set in (1), check the ! options section in

    /usr/share/X11/xkb/rules/*.lst
    

2nd Option

you can use the following script to get the same behavior in a session.

#!/bin/sh

# Super Caps

/usr/bin/setxkbmap -option 'caps:ctrl_modifier'  # rebind Caps_Lock to Ctrl, when held down, accomapgnied with other button
/usr/bin/xcape -e 'Caps_Lock=Escape'             # rebind Caps_Lock to Esp, when tapped alone
  1. put the above content in a file, in any location

e.g. custom_capslock in ~/.local/bin/

  1. make it executable

     chmod a+x custom_capslock
    
  2. add it to Startup Applications, by adding the FULL PATH of the script to Command field.

e.g /home/yourname/.local/custom_capslock

PS: if you want to use systemd or /etc/rc.local instead of "Startup Applications", make sure that your script didn't get overridden by other system services

| improve this answer | |

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.