Change Keyboard Layout for Other Process

SLaks picture SLaks · Nov 4, 2008 · Viewed 10.5k times · Source

I'm writing a program in C# that runs in the background and allows users to use a hotkey to switch keyboard layouts in the active window. (Windows only supports CTRL+SHIFT and ALT+SHIFT)

I'm using RegisterHotKey to catch the hotkey, and it's working fine.

The problem is that I can't find any API to change the keyboard layout for the focused window.

ActivateKeyboardLayout and LoadKeyboardLayout can only change the keyboard layout for the calling thread.

Does anyone know how to change the keyboard layout for a different thread (the way the Language Bar does)?

Answer

Ramil Mammadov picture Ramil Mammadov · Apr 22, 2010
PostMessage(handle, 
    WM_INPUTLANGCHANGEREQUEST, 
    0, 
    LoadKeyboardLayout( StrCopy(Layout,'00000419'), KLF_ACTIVATE)
);