GET the Input Language
You can use GetKeyboardLayoutList and GetKeyboardLayoutName to list Keyboard identifier.
Some code: (C++)
HKL hklArr[100];
int cnt = GetKeyboardLayoutList(100, hklArr);
if (cnt > 0)
{
for (UINT i = 0; i < cnt; i++)
{
if (ActivateKeyboardLayout(hklArr[i], 0))
{
CHAR pName[KL_NAMELENGTH];
if (GetKeyboardLayoutNameA(pName))
{
printf("layout name (KLID): %s
", pName);
}
}
}
}
Debug:
Then you can get the Input Language based on the keyboard identifier.
Refer:Keyboard Identifiers and Input Method Editors for Windows
SET the Input Language
Using WM_INPUTLANGCHANGEREQUEST message,
Some code:
HKL hkl = LoadKeyboardLayout(L"00000409", KLF_ACTIVATE);
PostMessage(GetConsoleWindow(), WM_INPUTLANGCHANGEREQUEST, 0, (LPARAM)hkl);
The keyboard will switch to "United States-English".
You can also set the INPUTLANGCHANGE_FORWARD parameter, it will use the hot key to select the next input locale in the list of installed input locales.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…