Key remapping in OSX and Linux: Capslock, Control/Escape, hjkl

Howto:

  1. map Capslock to Control as a modifier key, and as Escape when pressed alone;
  2. map left Control as something like a Fn key, so pressing Ctrl_L + hjkl produces arrow keys

OSX

Change Capslock to Control_L in Seil and use Karabiner to add the “single press to Escape” feature. Then swap Control_L and Control_R in Seil, and map Control_R as Fn. Then add Fn + hjkl as arrows.

  1. In Keyboard preferences, disable Capslock key as “No Action”
  2. In Seil, map keycodes of the following:
    1. capslock: 59
    2. Control_L: 62
    3. Control_R: 59
  3. In Karabiner, map the following:
    1. “Control_L to Control_L”
    2. “Control_R to Fn”
    3. “Fn+hjkl to Left/Down/Up/Right”

Linux (Ubuntu 16.04 LTS)

In xkb symbols, map Capslock as Control_L, and Control_L as AltGr. Also in xkb symbols, add arrows keys as a third layer to hjkl (to be invoked when combined with AltGr). Use xcape to allow single pressing Control_L as Escape.

  1. sudo vim /usr/share/X11/xkb/symbols/gb (or any suitable keyboard layout, like us), and add the following to xkb_symbols "basic"

    // hjkl
    // AltGr + hjkl
    key <AC06> { [    h, H, Left  ] };
    key <AC07> { [    j, J, Down  ] };
    key <AC08> { [    k, K, Up    ] };
    key <AC09> { [    l, L, Right ] };
    // modifer
    key <LCTL> { [ ISO_Level3_Shift  ] };
    key <CAPS> { [ Control_L  ] };
    
  2. build xcape from https://github.com/alols/xcape

  3. add the following to .bashrc

    setxkbmap -layout gb
    xcape -e 'Control_L=Escape'
    
    

Windows

Use autohotkey scripts.

Yi Liu
Senior research associate in health data science

data science, machine learning, and complex network analysis.

Related