Escape on Control key, Control on Capslock key, Capslock on Escape key

consolexkbxorg

I'm looking for a method that works in both X and the console with console-setup (e.g. xkboptions, no X-exclusive methods like xmodmap). With XKBoptions, combining ctrl:swapcaps and caps:swapescape does not achieve the desired effect – it puts control on capslock (good) and capslock on both the control and escape keys.

For the curious / confused, the rationale is to optimize the keyboard layout by putting more frequently used functions on easy to reach keys.

Since I never use capslock anyways I would also settle for a solution that puts Control on CapsLock and Escape on Control and leaves the Escape key as is (leaving me with no CapsLock function).

Best Answer

Adding a custom XKBOption

Debian uses the XKB system for both Xorg and console, so one method is to add a custom XKBOption. The relevant files on Debian are located under /usr/share/X11/xkb, files provided by the xkb-data package.

  1. Create symbols/custom

    // rotate the caps lock, left control, and escape keys so left control is on
    // the caps lock key
    partial modifier_keys
    xkb_symbols "rotatectrlcapsescape" {
        replace key <CAPS>      {  [ Control_L ] };
        replace key <LCTL>      {  [ Escape    ] };
        replace key <ESC>       {  [ Caps_Lock ] };
    };
    
  2. Modify rules/xorg: look for the section ! option = symbols and add

    custom:rotatectrlcapsescape = +custom(rotatectrlcapsescape)
    
  3. (Optional) Update rules/xorg.lst and rules/xorg.xml (exercise left to reader).

Now the custom:rotatectrlcapsescape custom XKBOptions is available for use. As per Debian instructions, this is configured by default in /etc/default/keyboard, with a simple XKBOPTIONS="custom:rotatectrlcapsescape".

Ubuntu/Gnome seems to use rules/evdev* instead of rules/xorg*.

Downsides

  • Modifying repository package files under /usr/ is rarely a good idea. The modified files will probably be clobbered the next time the owning package (xkb-data) updates.
Related Question