When modify the keyboard layout of explorer.exe by WM_INPUTLANGCHANGEREQUEST, the keyboard will always be automatically reverted to ENG
I am using SendMessage in AHK v2 (Sorry but I have not yet mastered the syntax for hooking the keyboard and using Windows API in other languages. ) to call WM_INPUTLANGCHANGEREQUEST
in order to create a quick input method switcher. When tested in other processes, everything works fine. Keyboard layout changed successfully.
But the Keyboard changed by WM_INPUTLANGCHANGEREQUEST
does not "persist" in Explorer.
Here is my test code:
#Requires AutoHotkey v2.0
; Change to Next Language Layout on ImmGetDefualtIMEWnd of current actived window
~LCtrl:: {
WM_INPUTLANGCHANGEREQUEST := 0x50
INPUTLANGCHANGE_FORWARD := 0x0002
ActivedhWnd := WinGetID("A") ; Get the actived Window's hWnd
SendMessage(WM_INPUTLANGCHANGEREQUEST, INPUTLANGCHANGE_FORWARD, , , DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", ActivedhWnd), 1000)
}
I have ensured that the "Let me use a different input method for each app window" option in Keyboard Settings is turned off, and I have double-checked the environment to ensure that only WM_INPUTLANGCHANGEREQUEST
is operating on the keyboard layout.
When I use WM_INPUTLANGCHANGEREQUEST
in Explorer to switch the input method, for example from ENG to Chinese, it switches normally. However, when I switch to another Explorer window (or switch to another any window then switch back), it immediately reverts to ENG.
If I use Win + Space
instead of WM_INPUTLANGCHANGEREQUEST
, it maintains the Chinese keyboard layout when switching to another Explorer window, which is the expected behavior.
That is to say, WM_INPUTLANGCHANGEREQUES
in Explorer seems to be only able to “temporarily” modify the keyboard, once the window is activated again, it will be automatically restored to the previous keyboard layout by the system.
Is this an issue inherent to WM_INPUTLANGCHANGEREQUEST
itself? Friends who use other programming languages, could you help me test the same implementation? Would this issue also occur in other programming languages? If so, how can we avoid this problem?
WM_INPUTLANGCHANGEREQUEST
has the advantage of being able to specify the language directly. My code above was changed to switch to the next keyboard layout just for convenience in illustrating the situation. I don’t want to use code to trigger hotkey like Win + Space
that only switch to the next input method, as it doesn’t meet my needs.