I would like to rebind some keys on Linux via Xmodmap. Left and up cursor on my Acer (yes, I know) laptop have broke. I would like to map shift+down to up, and shift+right to left. Struggling to determine the syntax for this from man pages. This syntax is wrong, throws bad modifier, but captures the intent:

add Shift_L+Down = Up

You can use:

keysym Down = Down Up

to do that. The keysym value is an ordered list of keysyms to use when unmodified, shifted, switched, shifted and switched, AltGr+key, shift-AltGr+key (all optional). Here unmodified Down is itself, while Shift-Down is bound to Up, and we don't set anything for the switched or AltGr modes.

There is a remaining problem: the Shift key is still pressed, so Shift-Down will be treated by applications the same way as Shift-Up. That may not be a problem for your use cases, but if you're going to use something that, say, uses shifted arrows for text selection, you'll have a problem. In that case there is another option:

keysym Down = Down Down Up Up

That binds both Down and Shift-Down as Down, and Mode_switch-Down and Mode_switch-Shift-Down to Up. Applications are unlikely to be listening to the Mode_switch key in the same way they do to Shift, so you don't get the double behaviour.

You then need to bind something to the Mode_switch keysym. I use:

keycode 66 = Mode_switch

which, on my keyboard, replaces Caps Lock, a key I don't have a use for. Caps Lock+Down now gives me Up as far as all my applications are concerned. You could rebind one of your shift keys instead if you preferred, but you'd lose the ordinary Shift modifier behaviour when you did.

There are actually more levels you can bind if you need, which use AltGr, and depending on your layout there can be yet another set of changes available. XCompose may also be useful to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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