I use 3 keyboard layouts in my Windows 10 laptop: English, Russian and Japanese. I use ru and en very often, and only from time to time I use jp, so I've decided to the following: set Capslock to cycle through ru and en and set win-j to call jp layout.
To do so I
Code: Select all
; Clever layout changer
; Define lang constats
ru := DllCall("LoadKeyboardLayout", "Str", "00000419", "Int", 1)
en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)
jp := DllCall("LoadKeyboardLayout", "Str", "00000411", "Int", 1)
Capslock::
w := DllCall("GetForegroundWindow")
pid := DllCall("GetWindowThreadProcessId", "UInt", w, "Ptr", 0)
l := DllCall("GetKeyboardLayout", "UInt", pid)
if (l = en)
{
PostMessage 0x50, 0, 0x4190419,, A
}
else
{
PostMessage 0x50, 0, 0x4090409,, A
}
return
; set japanese
#j::
PostMessage 0x50, 0, 0x4110411,, A
return
What is more interesting, is the fact that all other Autohotkey hotkeys work perfectly well in the windows specifed above. So I guess - just guessing - that the problem is with this PostMessage thing.
Anyone faced this issue? Any clues?
PS Running the sxript with admin rights does not fix this, I've tried to do it.