Are linux/input.h keycodes layout independent?

472 Views Asked by At

For example, in input.h, KEY_D is equal to 32. On a QWERTY keyboard, D is the third "printable" key from left on home row. On a DVORAK keyboard, the same key is marked E. So, if I press E on a DVORAK keyboard, will I get KEY_D (32) or KEY_E (18)?

1

There are 1 best solutions below

0
On BEST ANSWER

You will get KEY_D. These values are abstraction of keys as they are placed on a typical physical keyboard (see ISO 9995), after abstracting from all interface details (see e.g. three PC scancode sets and other mesh). But this does not take alternative layouts into account yet, neither national layouts like AZERTY nor special ones like Dvorak. They are implemented on the next layer, where independent keycodes are affected by modifiers and translated to resulting strings and events.

The USB "HID usage tables" document explicitly says:

Note A general note on Usages and languages: Due to the variation of keyboards from language to language, it is not feasible to specify exact key mappings for every language. Where this list is not specific for a key function in a language, the closest equivalent key position should be used, so that a keyboard may be modified for a different language by simply printing different keycaps. One example is the Y key on a North American keyboard. In Germany this is typically Z. Rather than changing the keyboard firmware to put the Z Usage into that place in the descriptor list, the vendor should use the Y Usage on both the North American and German keyboards. This continues to be the existing practice in the industry, in order to minimize the number of changes to the electronics to accommodate other languages.

so, if even your keyboard is initially Dvorak, you will get KEY_D. You can treat it as "generic" KEY_C03 (see again ISO9995 key names), if this satisfies (most XKB layout sources use this notation).