Question

I am writing a virtual keyboard application that reads windows KBD file to build the keyboard. I am having trouble understanding how to interpret the array of characters returned for each virtual key.

I am using the kbd.h files in this CodePlex project.

Here is the struct that I am not understanding.

typedef struct {
    PVK_TO_BIT pVkToBit;     // Virtual Keys -> Mod bits
    WORD       wMaxModBits;  // max Modification bit combination value
    BYTE       ModNumber[];  // Mod bits -> Modification Number
} MODIFIERS, *KBD_LONG_POINTER PMODIFIERS;

When reading the documentation, and analyzing the results with a US keyboard, this struct and its contained data makes sense.

---------------
US
---------------
CharModifiers
0001    = SHIFT
0010    = CTRL
0100    = ALT
ModNumber
0000    = 0     = BASE
0001    = 1     = SHIFT
0010    = 2     = CTRL
0011    = 3     = SHIFT + CTRL

What this says is that for the array of characters returned for each virtual key (another kbd.h struct), the first one represents no modifiers, the second represents the value when SHIFT is held, and so on. This is accurate and maps perfectly to the array of characters returned for each virtual key.

However, if I load a German keyboard layout (KBDGR.dll), the PMODIFIERS doesn't line up with array of characters returned for each virtual key.

---------------
German
---------------
CharModifiers
0001    = SHIFT
0010    = CTRL
0100    = ALT
ModNumber
0000    = 0     = BASE          = REALLY BASE
0001    = 1     = SHIFT         = REALLY SHIFT
0011    = 3     = SHIFT + CTRL  = REALLY ALTGR
0100    = 4     = ALT           = REALLY CTRL
1111    = 15    = INVALID       = INVALID
1111    = 15    = INVALID       = INVALID
0010    = 2     = CTRL          = REALLY SHIFT + CTRL
0101    = 5     = SHIFT + ALT   = REALLY SHIFT + ALTGR

As you can see here, for example, 0010 should correlate with just a CTRL modifier, however, the character returned from the virtual key really represents SHIFT + CTRL.

What am I not understanding? I thought that the array of ModNumber describes each index of characters for each virtual key, and the modifier keys they represent. This assumption worked correctly for the US keyboard layout, but when not for the German keyboard layout?

Was it helpful?

Solution

I emailed the makers of KbdEdit for their input, and they just replied with the answer!

The zero-based position within ModNumber array defines the modifier combination: eg, the last element "2" is at position 6, whose binary representation is 110, ie KBDCTRL | KBDALT, ie AltGr (www.kbdedit.com/manual/low_level_modifiers.html#AltGr) The value "2" means that AltGr mappings will appear at index 2 in all aVkToWchX[] arrays (for X>=3).

The position 3 corresponds to Shift+Ctrl (= 011 = KBDSHIFT | KBDCTRL) - you see that this combination is to be found at aVkToWchX[4] (for X>=5)

If you open the German layout in KbdEdit, you will see that indeed AltGr is at position 2, and Shift+Ctrl at position 4 (zero based) - see attached screenshot.

Hope this helps.

Regards, Ivica

Thanks Ivica!

OTHER TIPS

I've never figured out this either :) The description in the kbd.h-file didn't make much sense either, so I didn't bother to understand it.

In the kbd.h-header it states:

*                        CONTROL MENU SHIFT
*                           ^     ^     ^
*    aModification[] = {    |     |     |
*        0,            //   0     0     0     = 000 (none)

I belive the modifiers should be:
001 = SHIFT
010 = ALT
100 = CTRL

I agree that the list seems unlogical based in the german, and I reproduced it.

But I worked mostly on figuring out the connection between scan codes (physical placement) and virtual keys. Each virtual keys have the modifier included, that way you could iterate between all modifier combinations.

Since I'm Norwegian I handled the KBDNO.dll first, comparing it to the MKLC: http://msdn.microsoft.com/en-us/goglobal/bb964665.aspx

Since you asked for the German keyboard I also compared it, and it seems to match. Same with US.

Check out my "virtual keyboard" on my site: http://lars.werner.no/?page_id=922

The CKLL-class could help you a lot to achieve what you are trying to do. The class isn't perfect, so you have to put in some hours to get it there. Look at the keyboard as a array of scancodes with attached virtual keys based on modifiers :)

Sorry for not being more helpful atm, but it has been a while since I even programmed. To little spare time for my hobby!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top