Remapping Alt+left to Home with xkb

Hello !

I’m trying to remap the Alt+left key combination to Home (and Alt+right to End)

I’m using xkb using the following method :

xkbcomp $DISPLAY keymap.xkb
# change the file
xkbcomp keymap.xkb $DISPLAY

I’ve exported my keymap file and made the following changes to the left and right keys:

key <LEFT> {
        type[Group1] = "PC_ALT_LEVEL2",
        symbols[Group1]= [            Left,         Home ]
    };
    key <RGHT> {
        type[Group1]= "PC_ALT_LEVEL2",
        symbols[Group1]= [           Right,         End ]
    };

These changes seem to work because when I use xev I get the following output when I press Alt+left :

KeyPress event, serial 28, synthetic NO, window 0x3600001,
    root 0x60f, subw 0x0, time 1630131, (-175,845), root:(788,874),
    state 0x0, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyPress event, serial 28, synthetic NO, window 0x3600001,
    root 0x60f, subw 0x0, time 1630295, (-175,845), root:(788,874),
    state 0x8, keycode 113 (keysym 0xff50, Home), same_screen YES,
    XKeysymToKeycode returns keycode: 110
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x3600001,
    root 0x60f, subw 0x0, time 1630426, (-175,845), root:(788,874),
    state 0x8, keycode 113 (keysym 0xff50, Home), same_screen YES,
    XKeysymToKeycode returns keycode: 110
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x3600001,
    root 0x60f, subw 0x0, time 1630647, (-175,845), root:(788,874),
    state 0x8, keycode 64 (keysym 0xffe9, Alt_L), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

However, this doesn’t seem to produce the effect I want (moving caret to beginning of line)

I think something’s interfering, maybe the alt+left is recognized by someting else ? Do I have the wrong method for what I’m trying to achieve ?

Thanks in advance

Ok, sorry for posting before understanding this but I have now seen the “state” part in xev output, and I realise I’m typing Alt+home which is obviously not the same as just Home.

I need either to find a way to configure xkb to “unset” the state in this particular case or find a completely different solution. What do you think ?

1 Like

And here’s the solution I have found after more reasearch and trial :

So far it seems to do what I need (although there is now no way to do alt+left or ctrl+alt+left, I think I don’t use that anyway)

key <LEFT> {
           type= "PC_ALT_LEVEL2",
           symbols[Group1] = [            Left, Left ],
           actions[Group1] = [            NoAction(), RedirectKey(keycode=<HOME>, clearmods=Alt) ]
    };
    key <RGHT> {
        type="PC_ALT_LEVEL2",
        symbols[Group1] = [           Right, Right ],
        actions[Group1] = [           NoAction(), RedirectKey(keycode=<END>, clearmods=Alt) ]
    };
1 Like

It’s best to work around current configuration whenever possible. Alt + Left and Alt + Right can be useful, they change tabs in some software.

Perhaps third level shift would suffice, normally Alt Gr aka Right Alt. You’d need to configure it in your keyboard settings, there are several options to choose from (including Alt, but that would break the other functionality again).

If they don’t work for you, then you can assign the ISO_Level3_Shift keysym to an arbitrary key/level, for instance in the past I’ve had it assigned it to Insert.

type "PC_THIRDLEVEL_LEVEL2" {
    modifiers= LevelThree;
    map[LevelThree]= Level2;
    level_name[Level1]= "Base";
    level_name[Level2]= "AltGr";
};

key <LEFT> {
    type= "PC_THIRDLEVEL_LEVEL2",
    symbols[Group1] = [ Left, Left ],
    actions[Group1] = [ NoAction(), RedirectKey(keycode=<HOME>, clearmods=LevelThree) ]
};
key <RGHT> {
    type="PC_THIRDLEVEL_LEVEL2",
    symbols[Group1] = [ Right, Right ],
    actions[Group1] = [ NoAction(), RedirectKey(keycode=<END>, clearmods=LevelThree) ]
};

EDIT:

Removed partial advice about custom layout, as I currently don’t know where to put the type without editing a package owned file in /usr/share/X11/xkb/types.

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.