3

I want to use 'ijkl' together with alt to act like arrow keys. i.e. Alt+i = Up , Alt+K = Down etc.

I have tried xmodmap following this answer. The answer says that Alt modified key is the third column in xmodmap. Yet, xmodmap -e "keycode 31 = i I Up" does not assign up to Alt+i.

I have also tried xbindkeys following another answer. But this does not work as well.

"xvkbd -xsendevent -text '\[Left]'"
m:0x18 + c:44
alt + j

"xvkbd -xsendevent -text '[Down]'" m:0x18 + c:45 alt + k

"xvkbd -xsendevent -text '[Right]'" m:0x18 + c:46 alt + l

"xvkbd -xsendevent -text '[Up]'" m:0x18 + c:31 alt + i

I would much appreciate a solution, preferably that does not break other alt combinations that I have like ctrl+alt+t to open terminal etc.

edit: (if it helps for the answer) after I do xmodmap re-assignment when I run xev and press Alt+i it returns the following.

KeyPress event, serial 37, synthetic NO, window 0x2e00001,
    root 0x66b, subw 0x0, time 35626163, (161,-15), root:(261,144),
    state 0x10, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

FocusOut event, serial 37, synthetic NO, window 0x2e00001, mode NotifyGrab, detail NotifyAncestor

KeyPress event, serial 37, synthetic YES, window 0x2e00001, root 0x66b, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyRelease event, serial 37, synthetic YES, window 0x2e00001, root 0x66b, subw 0x0, time 0, (1,1), root:(1,1), state 0x1, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

KeyPress event, serial 37, synthetic YES, window 0x2e00001, root 0x66b, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 111 (keysym 0xff52, Up), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyRelease event, serial 37, synthetic YES, window 0x2e00001, root 0x66b, subw 0x0, time 0, (1,1), root:(1,1), state 0x0, keycode 111 (keysym 0xff52, Up), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

FocusIn event, serial 37, synthetic NO, window 0x2e00001, mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 37, synthetic NO, window 0x0, keys: 4294967216 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

KeyRelease event, serial 37, synthetic NO, window 0x2e00001, root 0x66b, subw 0x0, time 35628444, (161,-15), root:(261,144), state 0x18, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

First, I do not know why Shift_L shows up. Second, it shows that Up keypress even is registered somehow, yet it does not have any effect, for example it does not move the cursor up.

(I use Ubuntu 20.04)

adal
  • 31
  • Welcome to AskUbuntu, does this help? – Sadaharu Wakisaka Dec 10 '21 at 06:58
  • First, thank you. Second, the answer there refers to here which is what already what I did with xmodmap and it does not work. (I even tried to assign alt_l to Iso_level3_shift [which already broke all other alt+ shortcuts] yet it does not move the cursor as arrow keys supposed to do) – adal Dec 10 '21 at 13:23
  • you say that xmodmap -e "keycode 31 = i I Up" doesn't work, but did you also xmodmap -e "keycode 64 = Mode_switch"? – Andra Dec 27 '21 at 20:13
  • yes I did. But when I do that all other 'Alt' related shortcuts break. For example Ctrl+Alt+t is the binding that opens the terminal in Ubuntu, but when you remap Alt to Mode switch it no longer works. – adal Dec 30 '21 at 06:11

1 Answers1

0

I did this by editing the corresponding file in the /usr/share/X11/xkb/symbols directory. Since I use a German keyboard layout, for me this is this ./de file. I added/changed the following lines in the very first block:

xkb_symbols "basic" {

...

key <AD08> { [ i, I, Up, Up ] }; key <AC07> { [ j, J, Left, Left ] }; key <AC08> { [ k, K, Down, Down ] }; key <AC09> { [ l, L, Right, Right ] };

...

include "level3(alt_switch)"

};

The first few lines make it so that ALTGR + I = Up and so on, which is OK for me since I never use those combinations. Then the last line essentially makes ALT do the same as ALTGR. This does the job but is kinda uncool, since, as you mentioned, it messes up the other ALT combinations. My solution for this was simply not to use ALT for this but some other key that is in a good position and that I've never needed anyway: RWIN. In other words, I replaced the last line by

include "level3(rwin_switch)" 

This way, I can now press RWIN conveniently with my pinky to navigate with ijkl as arrow keys. The great thing is, unlike with some other solutions, you can still press, for example, SHIFT + RWIN + L to select text.

Hope this helps :)

mgns
  • 1