Keyboard Modifier Remapping

Keyboard

I'm a fairly heavy keyboard user, and now and then I experiment with new layouts and new techniques for improving my keyboard usage. Indeed, I began using the Dvorak layout many years ago.

Recently I've been revamping my emacs configuration, and realized that if I changed the location of the Control and Alt keys on my keyboard I could press them more easily with my thumbs, and even chord both keys together with a single thumb. Looking at my keyboard, I noticed that, on the left side, Alt is closest to the Spacebar and therefore the easiest to press with my left thumb. Next to it is the Windows key. On the right side of the keyboard, again Alt is closest to the Spacebar, with another Windows key right next to that.

My usage pattern is that I use Control all the time in emacs and the shell, I use Alt less often but still somewhat frequently in emacs, and I rarely use the Windows keys. Therefore, I decided to perform the remapping shown in Table Key Remapping:

Key Remapping
Before → After
Alt Control
Windows Alt
Control Windows

Windows

On Windows, Sharpkeys can remap modifier keys via a special registry entry on Windows. For some reason it cannot directly swap two keys, but luckily the above table is a rotation of three keys so it will work! You'll need to reboot for the new settings to take effect.

Caution!

Be very careful when remapping the Control and Alt keys since these are required for logging in on Windows. Don't mess them up!

Linux

On Ubuntu 14.04, the gnome-tweak-tool command allows the first two mappings to be achieved directly. Simply go to Typing ‣ Alt/Win key behavior and choose Ctrl is mapped Alt keys, Alt is mapped to Win keys and that's it. What to do about the Windows key? For now I do without it on Linux. This configuration is working fine on my Linux system at work.

Unfortunately, I ran into a problem with my home keyboard. Directly next to the right Alt key is a Menu key instead of a Windows key. Fixing this key to become a Control key required significantly more digging. I learned most of what I know from BLAENK.DENUM's post.

I won't repeat his fine explanations here, but I'll show what I needed to do for my situation. My goal was to make the mapping shown in Table Menu Key Remapping.

I created the file /usr/share/X11/xkb/symbols/rwb_menu_as_alt containing the following content:

partial hidden modifier_keys
xkb_symbols "rwb_menu_as_alt" {
  key <RCTL> { [ Menu ] };
  key <MENU> { [ Alt_R ] };
};

Next, I added these lines to the file /usr/share/X11/xkb/rules/evdev at the end of the section starting with ! option = symbols:

// RWB see /usr/share/X11/xkb/symbols/rwb_menu_as_alt for other part of this
  rwb_menu_as_alt:menu_as_alt_ctl_as_menu  = +rwb_menu_as_alt(menu_as_alt_ctl_as_menu)

Important

Be sure to backup the evdev file before modifying it. I usually name it something like evdev.orig.

Next, I used dconf-editor to add the left side of the previous line in the evdev file into the list value located at the key /org​/gnome​/desktop​/input-sources​/xkb-options. The resulting value in my dconf-editor looks like this:

['ctrl:nocaps', 'altwin:ctrl_alt_win', 'rwb_menu_as_alt:menu_as_alt_ctl_as_menu']

Conclusion

These settings are working well for me. It's been about 2 weeks since I made these keyboard layout changes and I'm mostly used to them now. It has relieved strain on my left pinky finger and I like having my left thumb get used for typing instead of its former habit of contributing nothing to my typing.

It's unfortunate that current operating systems only perform these types of mappings at fairly low levels. This was fine 20 years ago when it was nearly impossible to hook up two keyboards to a single PC. Today, it is trivial to attach another USB keyboard, but the registry settings on Windows (or the X settings shown on Linux) are not as easy to update for individual keyboards. Hopefully that will change as the use of bluetooth keyboards and other diverse input devices becomes more commonplace.

Comments

Comments powered by Disqus