C++ Windows - How to correctly detect if the keyboard layout is QWERTZ or AZERTY?

Viewed 268

I have got the following keyboard layouts in system:

enter image description here

I created the following QWERTZ / AZERTY detection function:

bool bIsAzertyKeyboard = false;
bool bIsQwertzKeyboard = false;
bool bIsQwertyKeyboard = false;
void DetectKeyboardType() {
    bIsAzertyKeyboard = false;
    bIsQwertzKeyboard = false;
    bIsQwertyKeyboard = true;
    switch (PRIMARYLANGID(LOWORD(GetKeyboardLayout(0))))
    {
    case LANG_FRENCH:
        bIsQwertyKeyboard = false;
        bIsAzertyKeyboard = true;
        break;
    case LANG_GERMAN:
        bIsQwertyKeyboard = false;
        bIsQwertzKeyboard = true;
        break;
    }
}

Unfortunately, I'm getting troubles detecting for the correct keyboard language, when it's a keyboard installed under a different language.

For example: bIsQwertzKeyboard is true only when the selected keyboard language is DEU. When I select ENG DE, the Y and Z are getting inverted, but bIsQwertzKeyboard is false.

How can I detect for the QWERTZ keyboard in all cases?

1 Answers

Looks like I solved it!

Replacing:

switch (PRIMARYLANGID(LOWORD(GetKeyboardLayout(0))))

to:

switch (PRIMARYLANGID(HIWORD(GetKeyboardLayout(0))))

does the trick! I was attempting to use the "SUBLANGID" instead, but that's something else.

Related