无法更改ahk_class的输入语言#32770

问题描述

我在PC上使用多种语言,并且经常使用自动热键在它们之间进行切换。

在一种情况下,我在弹出窗口中编写了一个脚本以切换为英语,以保存文件或网页,wintitle为ahk_class #32770。没用奇怪的是,相同的代码可用于ahk_exe Explorer.EXE窗口。

这是代码

#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,%en%,A
    send,{f4}
return

我做错了吗?

解决方法

DllCall可能不适用于所有程序。

尝试以下替代方法:

#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,% Lang,%CtrlInFocus%
}

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