实现不同窗口设置不同的输入法
;~shellhook=>wm_create=>getkeyboardlayout=>ImmSimulateHotKey 根据不同的程序窗口设置输入法,如键盘默认布局为英语(美国),运行脚本后,当开启Maxthon2,记事本,word,excel时,会设置输入法为QQ拼音。
;~ 我很不爽把输入法默认设为英文每次都要在文字输入时开启中文,或者把输入法默认设为中文后在某些程序和游戏中又要关闭一次。在本论坛和官网窜访了几次后做了这个脚本,一劳永逸了。
#Persistent
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage")
Return
ShellMessage( wParam,lParam ) {
If ( wParam = 1 )
{
WinGetclass, WinClass, ahk_id %lParam%
If Winclass in Notepad,OpusApp,XLMAIN,EVERYTHING,StandardFrame,UIWindowClassName.loach ,Container,TheWorld_Frame,IEFrame ;需要开启中文输入的窗口类名
{
winget,WinID,id,ahk_class %WinClass%
SetLayout("E0200804",WinID) ;E02b所 804是谷歌拼音代码,系统内安装的输入法代码可以在注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts查到
}
;~ If Winclass in Container,TheWorld_Frame,IEFrame ;需要开启中文输入的窗口类名
;~ {
;~ winget,WinID,id,ahk_class %WinClass%
;~ SetLayout("E0270804",WinID) ;E0270804是拼音++代码,系统内安装的输入法代码可以在注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts查到
;~ }
If Winclass in Progman ;需要关闭中文输入的窗口类名
{
winget,WinID,id,ahk_class %WinClass%
SetLayout("00000804",WinID) ;00000804是english代码,系统内安装的输入法代码可以在注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts查到
}
If Winclass in SciTEWindow ;需要中文输入法英文状态的,窗口类名
{
winget,WinID,id,ahk_class %WinClass%
SetLayout("E0200804",WinID)
Send,{Shift}
}
}
}
SetLayout(Layout,WinID){
DllCall("SendMessage", "UInt", WinID, "UInt", "80", "UInt", "1", "UInt", (DllCall("LoadKeyboardLayout", "Str", Layout, "UInt", "257")))
}
;~ HKL:=0x00000804
;~ HKL:=e0240804
;~ ControlGetFocus,ctl,A
;~ #4:: SendMessage,0x50,0,HKL,%ctl%,A
#Z::
Edit