1

How can I programmatically GET and SET the Input Language by WinAPI from Delphi (that can also be set from the Windows Taskbar):

enter image description here

Please note: The Input Language is NOT the language displayed in Windows UI. The Input Language is the language used by specific language-specific keyboard keys at the keyboard input.

1

1 Answer 1

2

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\n", pName);                  
            }
        }
    }
}

Debug:

enter image description here

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.