Cannot get current keyboard layout

I tried GetKeyboardLayoutName () and GetKeyboardLayout () to get the current keyboard layout, but they both give me the default layout, and changing the layout does not affect the output!

while(1)
{
    Sleep(5);
    for(int i = 8; i < 191; i++)
    {
        if(GetAsyncKeyState(i)&1 ==1)
        {
            TCHAR szKeyboard[KL_NAMELENGTH];
            GetKeyboardLayoutName(szKeyboard);

            if(GetAsyncKeyState(i)&1 ==1)
            {
                TCHAR szKeyboard[KL_NAMELENGTH];
                GetKeyboardLayoutName(szKeyboard);
                cout << szKeyboard << endl ;
            }
        }
    }
}

It always gives me “00000409” when the default layout is set to English, while I expect it to be “00000429” when I changed the layout to Farsi.

My first question is here, I used to find all my answers just by doing a search. But now I'm going crazy after hours of searching and getting nothing ...

+5
source share
1 answer

: GetKeyboardLayout (..) lang .

. , IE Alt + Shift, lang . ( )

, Alt + Tab ( foregorund), , lang .

, , .

, lang :

GUITHREADINFO Gti;
::ZeroMemory ( &Gti,sizeof(GUITHREADINFO));
Gti.cbSize = sizeof( GUITHREADINFO );
::GetGUIThreadInfo(0,&Gti);
DWORD dwThread = ::GetWindowThreadProcessId(Gti.hwndActive,0);
HKL lang = ::GetKeyboardLayout(dwThread);

GUITHREADINFO WINVER 0x500. stdafx.h .

#ifdef WINVER
#undef WINVER
#endif 
#define WINVER 0x500

source: GetKeyboardLayout (WINXP)

+7

All Articles