can't change input language for ahk_class #32770

419 views Asked by At

I use several languages on my PC, and I often use autohotkey to switch among them.

In one situation, I wrote a script to switch to English in the popup window for saving a file or a webpage, with wintitle being ahk_class #32770. It doesn't work. The strange thing is that the same code works for ahk_exe Explorer.EXE window.

Here's the code:

#NoEnv  
#Warn 
SendMode Input  
SetWorkingDir %A_ScriptDir%  

en := DllCall("LoadKeyboardLayout", "Str", "00000409", "Int", 1)

#if winactive("ahk_class #32770") or winactive("ahk_exe Explorer.EXE")
f4::
    PostMessage 0x50, 0, %en%,, A
    send,{f4}
return

Did I do something wrong?

1

There are 1 answers

0
Relax On BEST ANSWER

DllCall may not work in all programs.

Try this alternative:

#NoEnv  
#Warn 
SendMode Input  
SetWorkingDir %A_ScriptDir%  


#if winactive("ahk_class #32770") or winactive("ahk_exe Explorer.EXE")
f4::
    SetInputLang(0x0409) ; english 
    send,{f4}
return

SetInputLang(Lang){
    WinExist("A")
    ControlGetFocus, CtrlInFocus
    PostMessage, 0x50, 0, % Lang, %CtrlInFocus%
}

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=18519#p233011