user1581390
user1581390

Reputation: 1998

C++/Win32 Finding all keyboard input languages?

I want to find all the input languages for the keyboard, the ones that you switch between with LEFT ALT + SHIFT.

I can get the default locale and the installed/supported locales with win API but I could not find anywhere anything about the input locales for the keyboard.

Upvotes: 2

Views: 2929

Answers (1)

westwood
westwood

Reputation: 1774

You have to use GetKeyboardLayoutList function.

For example, to output in console all keyboard input languages you can use this code:

UINT uLayouts;
HKL  *lpList = NULL;
wchar_t szBuf[512];

uLayouts = GetKeyboardLayoutList(0, NULL);
lpList   = (HKL*)LocalAlloc(LPTR, (uLayouts * sizeof(HKL)));
uLayouts = GetKeyboardLayoutList(uLayouts, lpList);

for(int i = 0; i < uLayouts; ++i)
{
    GetLocaleInfo(MAKELCID(((UINT)lpList[i] & 0xffffffff), 
    SORT_DEFAULT), LOCALE_SLANGUAGE, szBuf, 512);
    wprintf(L"%s\n", szBuf);
    memset(szBuf, 0, 512);
}

if(lpList)
    LocalFree(lpList);

Upvotes: 9

Related Questions