c++ keyboards kbd.h need more information about processing the state of the modifier keys

89 views Asked by At

I am starting to work with keyboardlayouts on windows using kbd.h. I understood the part scancode->keycode via kbdxx.dll but struggle on the part of processing modifier keys (shift, Ctrl,Alt) especially how the binary coding of the states of those keys go along with the keycodes.

As the description in kbd.h is not helping me I am looking for more literature on this.

Where do I find more information about Keyboards especially the part where modifier keys come into place?

2

There are 2 answers

0
DJm00n On

There is no official documentation for keyboard layout format aside from kbd.h from SDK and sample keyboard layouts.

There is some unofficial description of these structs and flags: https://github.com/lelegard/winkbdlayouts

0
Ilya Zakharevich On

You need to be more specific which part of the layout you have problems with. The tables in a keyboard layout DLL are used to describe how to do the following tasks:

  • Translate a (essentially, 10-bit) scancode to a virtual code (usually by 3 static tables, for “prefixes” x00, xE0 and 0xE1; but it can also make it variable on Shift/Alt/Ctrl-modifiers, to a certain extent).
  • Translate a scancode to a keyname.
  • Translate the state of the pressed keys to “the current bitmap of 16 ‘modifier bits’”.
  • Translate the current bitmap to the ordinal of the column in the layout table.
  • Translate the VK_-name of the currently pressed key and the current column number to “an event”: either NOP, or a UTF-16 codepoint, or a state number of the keyboard FSM¹⁾, or the “lookup the long string event”.
  • If the FSM is not in the base state: translate “the assigned UTF-16 codepoint” (or “the assigned state ID”, or the consequent UTF-16 codepoints in the long string) of the currently pressed key to the new state of FSM, or to one UTF-16 codepoint-to-emit.
  • For the case of “long string event”, translate the VK_-name of the currently pressed key and the current column number to the sequence of UTF-16 codepoints.

¹⁾ This Finite State Machine is very limited in functionality.

I suspect you just need to see examples. The trivial ones would be produced by MSKLC (use its kbdutool to translate the .klc files created by the UI to C, if needed). Other examples of a non-trivial ones could be the C files (translated from ooo-us etc.) in this source distribution — I tried to put as much comment into the C files as humanly possible.

For “much more info than a real-beginner would want to see” see my docs