Knowing the layout doesn't mean knowing how to lay it out....

by Michael S. Kaplan, published on 2011/03/24 07:01 -04:00, original URI:

Over in the Suggestion Box, Marcus B. asked:

I currently have to delvelop an on-screen-keyboard at work. I wonder how the windows osk knows what keyboard type to display. I mean not the keyboard layout but the location and size of the return key and the surrounding keys. Is there any win API and where is this kind of information stored or is that a hardcoded feature for the windows osk?

Thank you :)

Sometimes the quickest answers are the most disappointing ones. :-(

There is no function one can call to tell you what layout to use for the emulation of the physical keys.

Generally there are just a few basic general types of layouts, and to solve this problem one would keep a list matching the KLID of the keyboard with the layout type. And of course have a general choice to use when an uknwon keyboard comes along....

For hardware itself it is kind of tied up in the use of GetKeyboardType, as I mentioned in Had I known that my last release would be *the* last release..., aka hindsight is 2020. Though as I mentioned in that very blog, despite the fact that there is a clear realationship between each keyboard layout DLL and the keyboard type information, this data is not directly exposed.

You can actually see it in the KBDTABLES structure defined in kbd.h, added to the end of the structure in Windows XP:


     * Type and subtype. These are optional.
    DWORD      dwType;     // Keyboard Type
    DWORD      dwSubType;  // Keyboard SubType: may contain OemId



Now in theory this means one could write a function to call the KbdLayerDescriptor function exported by the layout DLL (as previously described in I know that header file is around here somewhere and then you could get the dwType here and then by spending some time in the header file and with that Had I known that my last release would be *the* last release..., aka hindsight is 2020 blog, one could have a simple mapping of intended keyboard types for each layout and the way the keys themselves are laid out.

However, the fact that the tools (kbdtool.exe and kbdutool.exe) that are used to build the keyboard layout DLLs do not expose a direct method you can use to set these values, it is unclear how useful the data will be. The heuristics that are used to set the values are deterministic, but they are not documented....

I would deem the risk of it to ever change to be exceedingly low, since such a change could break all the existing layouts; given this it may be reasonably safe for someone to try to reverse engineer it if they wanted to. Though I had a tough time omin up with a ompelling reason to want to. YMMV!

In the end you're better off just storing a table, like I said. But that looked like way too short of a blog, and I knew someone would ask about GetKeyboardType....

Markus B. on 28 Mar 2011 3:39 AM:

Thank you for the answer. :)

As you said it's disappointing. I hoped that there is a easy and clean way for that. :/

I would guess that the windows osk uses a table for that.

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day