Just to add some detail of the accepted answer, here is what I see and what I did to make it work; will add more tricks and twists if I encounter them.
Using sudo dumpkeys
will give you output like this:
keycode 12 = minus
shift keycode 12 = underscore
shift altgr keycode 12 = underscore
control keycode 12 = Control_underscore
shift control keycode 12 = Control_underscore
altgr control keycode 12 = Control_underscore
shift altgr control keycode 12 = Control_underscore
alt keycode 12 = Meta_minus
...
And, if you open the keymap files under /lib/kbd/keymaps/xkb/
, you can see that in a line there is several (sometimes too many) columns like:
keycode 12 = U+002d U+005f U+002d U+005f Control_underscore Control_underscore Control_underscore ...
According to the man page of keymaps
: (man 5 keymaps
), we have:
Which of the actions bound to a given key is taken when it is pressed depends on what modifiers are in effect at that moment. The keyboard driver supports 9 modifiers. These modifiers are labeled (completely arbitrarily) Shift, AltGr, Control, Alt, ShiftL, ShiftR, CtrlL, CtrlR and CapsShift. Each of these modifiers has an associated weight of power of two according to the following table:
modifier weight
Shift 1
AltGr 2
Control 4
Alt 8
ShiftL 16
ShiftR 32
CtrlL 64
CtrlR 128
CapsShift 256
The effective action of a key is found out by adding up the weights of all the modifiers in effect. By default, no modifiers are in effect, so action number zero, i.e. the one in the first column in a key definition line, is taken when the key is pressed or released. When e.g. Shift and Alt modifiers are in effect, action number nine (from the 10th column) is the effective one.
Changing the state of what modifiers are in effect can be achieved by binding appropriate key actions to desired keys. For example, binding the symbol Shift to a key sets the Shift modifier in effect when that key is pressed and cancels the effect of that modifier when the key is released. Binding AltGr_Lock to a key sets AltGr in effect when the key is pressed and cancels the effect when the key is pressed again. (By default Shift, AltGr, Control and Alt are bound to the keys that bear a similar label; AltGr may denote the right Alt key.)
And we know U+002d
is Hyphen-Minus
, and U+005f
is low-line
, so we now see it clear: every line in keymap file, is the keycode and their keysys chars output when the key itself, shift+key, shift+altgr+key, ... is pressed, in that order.
(In case you forget the table, we can use dumpkeys --long-info
to show it).
They corresponds with each other: the lines in the first part corresponds with columns in the second part.
Better to view it in a table:
+----------+------------------------+----------------------------+
| | | |
| col. | key to press(+ keycode)| chars to produce (keysys) |
| | | |
+----------------------------------------------------------------+
| | | |
| 0 | keycode 12 | minus |
| | | |
+----------------------------------------------------------------+
| | | |
| 1 | shift | underscore |
| | | |
+----------------------------------------------------------------+
| | | |
| 2 | altgr | underscore |
| | | |
+----------------------------------------------------------------+
| | | |
| 3(1+2) | shift + altgr | underscore |
| | | |
+----------------------------------------------------------------+
| | | |
| 4 | ctrl | ctrl + underscore |
| | | |
+----------------------------------------------------------------+
| | | |
| 5(4+1) | ctrl + shift | ctrl + underscore |
| | | |
+----------+------------------------+----------------------------+
| | | |
| 6(4+2) | ctrl + alt | ctrl + underscore |
| | | |
+----------+------------------------+----------------------------+
GNOME
installed but deactivated(because when launching, I see a grey screen of GNOME and then I enter bash) , and I read somewhere that I must enter/usr/share/X11/xkb
to change settings for GNOME. The changes to files/lib/kbd/keymaps
applies toxkb
, too? Or they are independent? Under my situation, which takes precedence? – WesternGun Oct 26 '17 at 10:19setxkbmap
) as long as your desktop manager does not overwrite it (for Gnome, check this). – WhiteWinterWolf Oct 26 '17 at 10:35/usr/lib/kbd/keymaps/xkb/
, and/lib/kbd/keymaps/xkb/
as well. Any difference? – WesternGun Nov 14 '17 at 17:03loadkeys <name>
, and it is loaded, and when I runlocalectl
, I seeVC
is using my keymap, but when I press the keys, they are in US-keyboard position. – WesternGun Nov 16 '17 at 12:04xxx.map
file to meet my needs, substitute every keycode to what I want (in one line there are more than 30 repeative key codes). – WesternGun Jan 15 '18 at 17:02