Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

How to programmatically GET and SET the Input Language by WinAPI from Delphi?

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.

question from:https://stackoverflow.com/questions/65888832/how-to-programmatically-get-and-set-the-input-language-by-winapi-from-delphi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...