简体   繁体   中英

Detect if the keyboard layout has AltGr on it under Windows

Does anyone know a good method how we can check from code in C/C++ if the actual keyboard layout has the ALTGR key or not on it?

I think the best method would be to read and interpret the keyboard layout file eg "KBDGR.DLL" for german but the API to do this does not exists and that what exists is not well documented.

Is there any other way to do this?

I know it's been a while - This is the best I came up with

BOOL CMonitor::LayoutHasAltGr(HKL keyboard_layout)
{
    BOOL hasAltGr = FALSE;
    int scancode;

    for (WORD i = 32; i < 256; ++i)
    {
        scancode = VkKeyScanEx((TCHAR)i, keyboard_layout);
        if (scancode != -1 && (scancode & 0x600) == 0x600)
        {
            // Ctrl + Alt means AltGr
            hasAltGr = TRUE;
            break;
        }
    }

    return hasAltGr;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM