up vote 5 down vote favorite
5
share [g+] share [fb]

I'm trying to map:

Super+h -> Left
Super+j -> Down
Super+k -> Up
Super+l -> Right

globally under X. The idea is I don't want to leave my home row that often to use the arrow keys, so I'll use the Super modifier + hjkl to emulate the arrow keys under X. Is there any way to do this?

One thing I've tried is xbindkeys + xte using this configuration:

"xte 'keydown Up' 'keyup Up'"
  Mod4+k

"xte 'keydown Down' 'keyup Down'"
  Mod4+j

"xte 'keydown Left' 'keyup Left'"
  Mod4+h

"xte 'keydown Right' 'keyup Right'"
  Mod4+l

but there seems to a large delay between me pressing the key and noticing any result, and most of the time nothing happens at all.

Is there a more elegant way of doing this that actually works with no delay?

link|improve this question
2  
Have found this to be great for doing this sort of thing: code.google.com/p/autokey – Tom Power Dec 2 '11 at 12:16
What is the OS? I also think you might be better off using Control-Super or some such combo. – harrymc Feb 4 at 8:39
feedback

This question had a bounty worth +50 reputation from dotancohen that ended 5 hours ago; grace period ends in 18 hours

The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.

None of the provided answers provide the ability to use Super with hjkl as arrow keys. Mapping the physical Win key to something other than Super breaks applications that do use Super. Using CapsLock is not viable for those who really do need CapsLock. ScrollLock is not viable as it is not on the home row, the whole purpose of this question is to keep the fingers on the home row.

3 Answers

I found this blog comment describing what I wanted to do, except it maps hjkl to the arrow keys when capslock is down, which might be a better idea anyways:

Okay, I got it working on my Linux laptop, if not supremely elegantly. Evidently there is some overlapping of tasks between xkb and xmodmap under Xorg, so just setting the settings in xmodmap wasn’t doing the trick.

First I made an ~/.Xmodmap file to turn my Caps Lock key into a modifier:

clear Lock 
keycode 66 = ISO_Level3_Shift

Then I modified the first stanza of my /usr/share/X11/xkb/symbols/us file to add the keymappings I wanted:

key { [ h, H, Left ] }; 
key { [ j, J, Down ] };
key { [ k, K, Up ] }; 
key { [ l, L, Right ] };

I saved both files and activated the changes with setxkbmap ; xmodmap ~/.Xmodmap

And it works great! Thanks for the idea — it’s a real time-saver.

I don’t think you’d need a kernel module to make it work on the console; I think the built-in loadkeys can handle that.

http://duartes.org/gustavo/blog/post/home-row-computing/comment-page-1#comment-13209

link|improve this answer
feedback

I haven't tried this myself but it looks like xkb might do what you want http://en.wikipedia.org/wiki/X_keyboard_extension.

I have a package in Ubuntu called x11-xkb-utils that sounds promising :)

link|improve this answer
xkb cannot work with the Super key as a modifier. xkb only works with (in order) Unmodified, Shift, AltGr, Shift-AltGr. Higher-level modifiers can also be assigned (such as in Bill Casarin's CapsLock example) but they do not come on a standard keyboard. Mapping Super to a higher modifier removes it from functioning as Super (as in basic6's example). – dotancohen Feb 3 at 23:06
feedback

The above mentioned changes in /usr/share/X11/xkb/symbols/us do NOT work for me:
Error loading new keyboard description

But after looking through lots of contradicting howtos, I've come up with a solution, which maps the left super key (left windows key / Mod4) in combination with hjkl to Left, Down, Up, Right. This is a system-wide setting.

Add this block to the end of the first section (right before };) of your /usr/share/X11/xkb/symbols/us:

//hjkl
//AltGr + hjkl
key <AC06> {        [         h, H, Left            ]       };
key <AC07> {        [         j, J, Down            ]       };
key <AC08> {        [         k, K, Up              ]       };
key <AC09> {        [         l, L, Right           ]       };
//Super_L -> Alt Gr
key <LWIN> { [ ISO_Level3_Shift ] }; //see below!

The first key line maps AltGr+h to Left.
The last key line makes the left super key behave like AltGr.
Here you go:

Super + h -> Left
Super + j -> Down
Super + k -> Up
Super + l -> Right

In order to apply the new settings, run setxkbmap or restart your system.

Important: This obviously disables the super key, so if you're actually using your super key for other purposes (i.e. moving a window to another workspace), you shouldn't remap it like this.
In order to use Caps Lock instead of Super, change the last key line with:

key <CAPS> { [ ISO_Level3_Shift ] };

Here's the complete first section of my config file:

default
partial alphanumeric_keys modifier_keys
xkb_symbols "basic" {

    name[Group1]= "English (US)";

    // Alphanumeric section
    key <TLDE> {        [     grave,    asciitilde      ]       };
    key <AE01> {        [         1,    exclam          ]       };
    key <AE02> {        [         2,    at              ]       };
    key <AE03> {        [         3,    numbersign      ]       };
    key <AE04> {        [         4,    dollar          ]       };
    key <AE05> {        [         5,    percent         ]       };
    key <AE06> {        [         6,    asciicircum     ]       };
    key <AE07> {        [         7,    ampersand       ]       };
    key <AE08> {        [         8,    asterisk        ]       };
    key <AE09> {        [         9,    parenleft       ]       };
    key <AE10> {        [         0,    parenright      ]       };
    key <AE11> {        [     minus,    underscore      ]       };
    key <AE12> {        [     equal,    plus            ]       };

    key <AD01> {        [         q,    Q               ]       };
    key <AD02> {        [         w,    W               ]       };
    key <AD03> {        [         e,    E               ]       };
    key <AD04> {        [         r,    R               ]       };
    key <AD05> {        [         t,    T               ]       };
    key <AD06> {        [         y,    Y               ]       };
    key <AD07> {        [         u,    U               ]       };
    key <AD08> {        [         i,    I               ]       };
    key <AD09> {        [         o,    O               ]       };
    key <AD10> {        [         p,    P               ]       };
    key <AD11> {        [ bracketleft,  braceleft       ]       };
    key <AD12> {        [ bracketright, braceright      ]       };

    key <AC01> {        [         a,    A               ]       };
    key <AC02> {        [         s,    S               ]       };
    key <AC03> {        [         d,    D               ]       };
    key <AC04> {        [         f,    F               ]       };
    key <AC05> {        [         g,    G               ]       };
    key <AC06> {        [         h,    H               ]       };
    key <AC07> {        [         j,    J               ]       };
    key <AC08> {        [         k,    K               ]       };
    key <AC09> {        [         l,    L               ]       };
    key <AC10> {        [ semicolon,    colon           ]       };
    key <AC11> {        [ apostrophe,   quotedbl        ]       };

    key <AB01> {        [         z,    Z               ]       };
    key <AB02> {        [         x,    X               ]       };
    key <AB03> {        [         c,    C               ]       };
    key <AB04> {        [         v,    V               ]       };
    key <AB05> {        [         b,    B               ]       };
    key <AB06> {        [         n,    N               ]       };
    key <AB07> {        [         m,    M               ]       };
    key <AB08> {        [     comma,    less            ]       };
    key <AB09> {        [    period,    greater         ]       };
    key <AB10> {        [     slash,    question        ]       };

    key <BKSL> {        [ backslash,         bar        ]       };
    // End alphanumeric section

    //hjkl
    //AltGr + hjkl
    key <AC06> {        [         h, H, Left            ]       };
    key <AC07> {        [         j, J, Down            ]       };
    key <AC08> {        [         k, K, Up              ]       };
    key <AC09> {        [         l, L, Right           ]       };
    //Super_L -> Alt Gr
    key <LWIN> { [ ISO_Level3_Shift ] };


};

I hope this helps somebody out there...

If anyone has a better solution, please let me know.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.