Ubuntu – Overload capslock with esc and ctrl using xcape

xmodmap

I want to:

  1. Turn off capslock when hitting the capslock key
  2. Escape when hitting the capslock key
  3. Behave like ctrl when pressing down the capslock key

What I have in my ~/.Xmodmap:

!Set Capslock to LCtrl
remove Lock = Caps_Lock
remove Control = Control_L
keycode 66 = Control_L
add Control = Control_L

!Set Escape to Capslock
keycode 9 = Caps_Lock
add Lock = Caps_Lock

!Dummy Escape Key for XCape
keycode 254 = Escape

What I have at the end of my ~/.profile:

$HOME/xcape/xcape -e 'Control_L=Escape' # Run xcape after login

Things work mostly as expected with just Xmodmap, and mostly as expected with Xmodmap + $HOME/xcape/xcape -e 'Control_L=Escape' when not run from .profile.

I get some strange behaviors when it runs from .profile; capslock key still toggles capslock in addition to behaving as esc and ctrl. My left ctrl exhibits this exact behavior as well.

Maybe I should be running this from somewhere other than .profile?

Edit: tried running $HOME/xcape/xcape -e 'Control_L=Escape' from xubuntu's menu -> settings manager -> Session and Startup -> Application Autostart with no effect at all.

Best Answer

.Xmodmap:

clear lock
clear control
keycode 66 = Control_L
add control = Control_L Control_R

Under Settings > Session and Startup > Application Autostart > Add:

/path/to/xcape -e 'Control_L=Escape'

This works with the side effect of LCtrl also escaping when tapped. Not perfect but hasn't bothered me enough to fix it in the years I've used it.