不同窗口自動設置輸入法

實現不同窗口設置不同的輸入法

;~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


發佈了19 篇原創文章 · 獲贊 9 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章