Answer the question
In order to leave comments, you need to log in
What recipient should be specified for the WM_INPUTLANGCHANGEREQUEST message?
In my layout switcher, I encountered the problem of switching layouts in Skype (judging by the reviews, this is not the only program in which this behavior is observed). The problem is rather strange: if there is only one letter in the message box, everything works as it should, otherwise the WM_INPUTLANGCHANGEREQUEST message is not processed. Message sending code:
public static void SetNextKeyboardLayout()
{
IntPtr hWnd = GetForegroundWindow();
uint processId;
uint activeThreadId = GetWindowThreadProcessId(hWnd, out processId);
uint currentThreadId = GetCurrentThreadId();
AttachThreadInput(activeThreadId, currentThreadId, true);
IntPtr focusedHandle = GetFocus();
AttachThreadInput(activeThreadId, currentThreadId, false);
PostMessage(focusedHandle == IntPtr.Zero ? hWnd : focusedHandle, WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, HKL_NEXT);
}
Answer the question
In order to leave comments, you need to log in
In my switch, I use this piece of code (collected from the world by thread)
void function()
{
var threadInfo = new WinAPI.GUITHREADINFO();
threadInfo.cbSize = Marshal.SizeOf(threadInfo);
WinAPI.GetGUIThreadInfo(0, ref threadInfo);
IntPtr hWnd = (threadInfo.hwndFocus != IntPtr.Zero) ? threadInfo.hwndFocus : threadInfo.hwndActive;
WinAPI.PostMessage(hWnd, WinAPI.WM_INPUTLANGCHANGEREQUEST, WinAPI.WM_INPUTLANGCHANGE_SYSCHARSET, (int)_seconLayot);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question