Can I map Control to the Caps Lock key and keep the toggle functionality in Linux?

0

Can I change the Caps Lock key to Control and still keep the on/off nature of Caps Lock? I've checked into using xmodmap and seem to have hit a dead end. Many people want to swap them, but they also want to swap the way they work. I'd rather keep my new Control key as an on/off switch for Control.

MalcolmWhy

Posted 2010-10-13T18:00:31.217

Reputation: 3

Answers

0

There's no low-level support for a Ctrl Lock in either Linux or Xorg outside of bugs, so you'll either need software that will feed the Ctrl press back into some input buffer in order to simulate a lock, or you'll need a keyboard that supports it directly.

Ignacio Vazquez-Abrams

Posted 2010-10-13T18:00:31.217

Reputation: 100 516

Thanks, at least now I know not to keep trying to do it by messing with keymappings. – MalcolmWhy – 2010-10-18T19:57:55.863

1

As Ignacio said, it cannot be done with keymaps. But it can be e.g. simply scripted using xbindkeys and xdotool.

First, strip Caps Lock of its special functionality using xmodmap (this has to be done each time X is started):

xmodmap -e 'keycode 66 = F13'

Then, add the following bindings to you .xbindkeysrc:

"xdotool keyup Control_L; xdotool keydown Control_L"
    F13
"xdotool keydown Control_L; xdotool keyup Control_L"
    Control + F13

This creates a fake keypress (without release) of the Ctrl key whenever Caps Lock (now F13) is pressed. The up+down sequence is there for some technical reasons of how the fake events work.

In this version, pressing (left) Ctrl releases the lock. This could be modified (either so that both controls release it, or neither does) but it would be a little more complicated (e.g. one could create another control key (e.g. F14) and fake-press that instead of Control_L).

regnarg

Posted 2010-10-13T18:00:31.217

Reputation: 171