Windows 10 + multiple layouts switcher

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
popobawa
Posts: 2
Joined: 18 Jan 2018, 10:24

Windows 10 + multiple layouts switcher

20 Jan 2018, 10:48

Problem:
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 wrote copy-pasted the following code I found here on the forum:

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
And it works of a sort! It worked perfectly well in windows 8.1. It still works in windows 10 but here comes the problem: not in every window. Let's say it does not work in windows store window. No idea why. It doesn not work in Run window (that thing appearing after win-r). It does not work when UAC asks me for admin password if I need to run something with admin rights.
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.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], Rohwedder, slowwd and 225 guests