xmodmap shift + keycode to produce keysym

There seem to be few examples for how to use xmodmap to bind a modifier + some key, to a new key.

E.g. I want to bind left Shift (keycode 50) + ` (keycode 21) to emit a grave accent character:


This is the normal behavior for a Norwegian keyboard, but not on a Macbook Pro (running Linux).

I’m using xev to get the keycodes, I can successfully map single key presses (with the help from another post which I cannot find) to get essential other keys, e.g. backspace and dollar sign in this manner:

keycode 134 = ISO_Level3_Shift Multi_key ISO_Level3_Shift Multi_key
keycode 21 = backslash bar

However how do I do:

keycode 50 + keycode 21 = Grave character

This is not the correct syntax but it should make what I want clear.

In general how is a modifier key like shift used correctly in the syntax? Can only modifier keys be used in combinations?

I’ve tried simple things such as “keycode 50 keycode 21 = A” and “keycode 50 + keycode 21 = A”. (“A” is not the character I want, I’m just using it for test purposes).

Key chords (like Shift+) are specified by combining one key with a set of modifiers, not by combining keys directly. So rather than “keycode 50 plus keycode 21”, what you need to specify is “keycode 21 plus the Shift modifier”. Only modifiers can be used in combinations. Furthermore xmodmap is somewhat limited: you need to specify all the key chords for a particular base key at the same time.

keycode 21 = backslash grave acute

The first keysym (character or function key name) after the equal sign is the one corresponding to the bare key, then comes the one corresponding to the key with Shift, then with AltGr, then with Shift+AltGr.

If you want dead keys, then change this to

keycode 21 = backslash dead_grave dead_acute

If you want a standard Norwegian layout, though, you should be able to select it in your desktop environment’s configuration interface, or with XKB — setxkbmap -layout no switches to a Norwegian layout.

Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.