Skip to main content
added 1759 characters in body
Source Link
WesternGun
  • 632
  • 1
  • 7
  • 19

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.)

(In case you forget the table, we can use dumpkeys --long-info will give us this table:to show it).

Recognized modifier names and their column numbers:

shift             1
altgr             2
control           4
alt               8
shiftl           16
shiftr           32
ctrll            64
ctrlr           128
capsshift               256
+----------+------------------------+----------------------------+
|          |                        |                            |
|  col.    | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   10      | keycode 12             | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   21      | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   42      | shiftaltgr + altgr                | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   8     3(1+2) | ctrl shift + altgr          | underscore     | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   164      | shiftctrl + ctrl                 | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   5(4+1) | ctrl + shift           | ...ctrl + underscore          |
|          | ...                       |                            |
+----------+------------------------+----------------------------+
|          |                        |                            |
|   6(4+2) | ctrl + alt             | ctrl + underscore          |
|          |                        |                            |
+----------+------------------------+----------------------------+

dumpkeys --long-info will give us this table:

Recognized modifier names and their column numbers:

shift             1
altgr             2
control           4
alt               8
shiftl           16
shiftr           32
ctrll            64
ctrlr           128
capsshift               256
+----------+------------------------+----------------------------+
|          |                        |                            |
|  col.    | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   1      | keycode 12             | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   2      | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   4      | shift + altgr          | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   8      | ctrl                   | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   16     | shift + ctrl           | ctrl + 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.)

(In case you forget the table, we can use dumpkeys --long-info to show it).

+----------+------------------------+----------------------------+
|          |                        |                            |
|  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          |
|          |                        |                            |
+----------+------------------------+----------------------------+
added 341 characters in body
Source Link
WesternGun
  • 632
  • 1
  • 7
  • 19

dumpkeys --long-info will give us this table:

Recognized modifier names and their column numbers:

shift             1
altgr             2
control           4
alt               8
shiftl           16
shiftr           32
ctrll            64
ctrlr           128
capsshift               256
+----------+------------------------+----------------------------+
|          |                        |                            |
| key codecol.    | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   12     |   1      | keycode 12             | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|    2      | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|    4      | shift + altgr          | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|    8      | ctrl                   | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|     16     | shift + ctrl           | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ...                    | ...                        |
|          |                        |                            |
+----------+------------------------+----------------------------+
+----------+------------------------+----------------------------+
|          |                        |                            |
| key code | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   12     |                        | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift + altgr          | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ctrl                   | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift + ctrl           | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ...                    | ...                        |
|          |                        |                            |
+----------+------------------------+----------------------------+

dumpkeys --long-info will give us this table:

Recognized modifier names and their column numbers:

shift             1
altgr             2
control           4
alt               8
shiftl           16
shiftr           32
ctrll            64
ctrlr           128
capsshift               256
+----------+------------------------+----------------------------+
|          |                        |                            |
|  col.    | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   1      | keycode 12             | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   2      | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   4      | shift + altgr          | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   8      | ctrl                   | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   16     | shift + ctrl           | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ...                    | ...                        |
|          |                        |                            |
+----------+------------------------+----------------------------+
Source Link
WesternGun
  • 632
  • 1
  • 7
  • 19

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 ...

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.

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:

+----------+------------------------+----------------------------+
|          |                        |                            |
| key code | key to press(+ keycode)| chars to produce (keysys)  |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|   12     |                        | minus                      |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift                  | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift + altgr          | underscore                 |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ctrl                   | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | shift + ctrl           | ctrl + underscore          |
|          |                        |                            |
+----------------------------------------------------------------+
|          |                        |                            |
|          | ...                    | ...                        |
|          |                        |                            |
+----------+------------------------+----------------------------+