SwapControlAltAndCapsLock

Swapping Control and CapsLock is all well and good, but it often feels like it doesn’t go far enough. Keyboard shortcuts seem to have been written with old Unix and Sun keyboards in mind, where Control and Alt were reversed. Since resoldering a keyboard isn’t an option for most people, why not just swap Control and Alt programatically to use the keyboard the way it was meant to be used?

This works especially well if you turn CapsLock into a Control key, effectively giving you two Control keys under your thumbs and three Alt keys, one of which is immediately under your left pinky.

Warning: This really will blow your mind for a week or so, especially if you’re a touch-typist or use Emacs through muscle-memory (you think of keystrokes conceptually, like “new file”, not as keystrokes, like “opening a new file is C-x C-f”). However, it’s so much easier to use that I think it’s worth it. In addition, it may help to avoid “Emacs pinky” (RepeatedStrainInjury).

Windows

Registry and AutoHotKey Method

This method is two steps long. First, you map the CapsLock key to a Control key (Left-Control, I believe), and then you swap the Control and Alt keys (including your new CapsLock-now-Control key).

Converting Caps to Control

Save the following as ``caps2ctrl.reg`` and then run it::

REGEDIT4

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00

Now, restart your machine.

Swapping ALL Control and Alt Keys

Install AutoHotKey and save the following as “swap_ctrl_alt.ahk” and then run it:

LCtrl::Alt
LAlt::Ctrl
RCtrl::Alt
RAlt::Ctrl

You’ll have to put “swap_ctrl_alt.ahk” in your Startup folder if you want the keys swapped every time you log in.

Ctrl2cap

Ctrl2cap is a kernel-mode device driver that filters the system’s keyboard class driver in order to convert caps-lock characters into control characters.

http://technet.microsoft.com/en-us/sysinternals/bb897578.aspx

Linux Virtual Terminals

Debian

Download “lisp-emacs-us.kmap.gz” from my Emacs Keymap project [1].

Put that file in:

/usr/share/keymaps/i386/qwerty/

Then, edit your “/etc/rc.local” file to include the line:

loadkeys /usr/share/keymaps/i386/qwerty/lisp-emacs-us.kmap.gz

A Bit More Extreme

I have been using a similar configuration for the past few months, but I remap the bottom row as:

Super - Meta - Ctrl - Space - Ctrl - Meta - Meta - Super

Attached are the scripts for Windows and *nix. Note that I have only tested this with Debian Squeeze on amd64 with the US and Dvorak keyboard layouts, and on Windows XP.

I have set both Super_R (Windows) & Menu to Alt_R, as some laptop (Asus) and ‘modern’ keyboards don’t have Super_R keys, just Menu. I only use Super keys for window manager shortcuts anyway, YMMV.

Setting CapsLock as Alt_L also makes some of the C-M keystrokes easier.

*nix

Xmodmap file for *nix:

! output taken from:
! xmodmap -pke | egrep '(Control|Super|Alt|Menu)'
! Use to set keycodes correctly below. List reordered to match
! keys from left to right.

! keycode  66 = CapsLock
! keycode  37 = Control_L NoSymbol Control_L
! keycode 133 = Super_L NoSymbol Super_L
! keycode  64 = Alt_L Meta_L Alt_L Meta_L
! keycode 108 = Alt_R Meta_R Alt_R Meta_R
! keycode 134 = Super_R NoSymbol Super_R
! keycode 135 = Menu
! keycode 105 = Control_R NoSymbol Control_R

! First clear all modifiers, caps lock & control
clear lock
clear control
clear mod1
clear mod4

keycode  66 = Alt_L Meta_L
keycode  37 = Super_L
keycode 133 = Alt_L Meta_L
keycode  64 = Control_L
keycode 108 = Control_R
keycode 134 = Alt_R Meta_R
keycode 135 = Alt_R Meta_R
keycode 105 = Super_R

! We need to set keycodes first, as some programs (emacs!) read
! the key names and seem to ignore what's below.
add mod1    = Alt_R Alt_L Meta_R Meta_L
add mod4    = Super_R Super_L Menu
add control = Control_R Control_L

Windows

For Windows, enter the following into an autohotkey script. The final line is required to make Alt+Tab work correctly, it’s on the autohotkey wiki.

LWin::LAlt
LAlt::LCtrl
LCtrl::LWin
LCtrl up::Send {LCtrl Up}

RAlt::RCtrl
RWin::RAlt
AppsKey::RAlt
RCtrl::AppsKey

CapsLock::LAlt
*Tab::Send {Blind}{Tab}

Personally I find it much easier to use emacs shortcuts with this configuration, although the changeover is hard. C-M shortcuts are a bit of a pain, but normally I tilt my thumb over the two keys to press them together.

+1 for this configuration. I’ve been using almost exactly the same for years now and I’m very satisfied with it. It makes a lot of sense once you have a look at the layout of the Space Cadet keyboard, which is one of the keyboards on which Emacs was originally developed.

The only difference in my case is the second Meta on the right (the menu key originally): I use that key for ISO_Level3_Shift instead, for typing national characters and the like.

j.a.


CategoryKeys CategoryAccessibility