Skip to content

Instantly share code, notes, and snippets.

@emisjerry
Created September 29, 2019 07:14
Show Gist options
  • Save emisjerry/056ca22797d5f2fc7af14c9e9fa18df6 to your computer and use it in GitHub Desktop.
Save emisjerry/056ca22797d5f2fc7af14c9e9fa18df6 to your computer and use it in GitHub Desktop.
使用AutoHotkey快速切換語言鍵盤,和超難用的Ctrl/Alt+Shift說再見!(AHK #9)
#SingleInstance Force
!1::
SetDefaultKeyboard(0x0409) ;; 切換為英文輸入
return
!2::
SetDefaultKeyboard(0x0404) ;; 切換為中文輸入
return
!0::
V++
M := mod(V,2) ;; 模數
if M=1
SetDefaultKeyboard(0x0404) ;; 切換為中文輸入
else
SetDefaultKeyboard(0x0409) ;; 切換為英文輸入
return
SetDefaultKeyboard(LocaleID) {
Global SPI_SETDEFAULTINPUTLANG := 0x005A
SPIF_SENDWININICHANGE := 2
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "Int", 0)
VarSetCapacity(Lan%LocaleID%, 4, 0)
NumPut(LocaleID, Lan%LocaleID%)
;Lan := 0xE0090404
DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", &Lan%LocaleID%, "UInt", SPIF_SENDWININICHANGE)
WinGet, windows, List
Loop %windows% {
PostMessage 0x50, 0, %Lan%, , % "ahk_id " windows%A_Index%
}
}
@agqduejko
Copy link

AHK的2.0寫法,應該是這樣,也讓大家參考一下
;=======================================
;設定輸入法
;=======================================
設定輸入法(LocaleID) {
SPI_SETDEFAULTINPUTLANG := 0x005A
SPIF_SENDWININICHANGE := 2
Lan := DllCall("LoadKeyboardLayout", "Str", Format("{:08x}", LocaleID), "UInt", 0)
LocaleID_Buffer := Buffer(4)
NumPut("UInt", LocaleID, LocaleID_Buffer)
DllCall("SystemParametersInfo", "UInt", SPI_SETDEFAULTINPUTLANG, "UInt", 0, "UPtr", LocaleID_Buffer.Ptr, "UInt", SPIF_SENDWININICHANGE)
windows := WinGetList()
For windowID in windows {
PostMessage(0x50, 0, Lan, , "ahk_id " . windowID)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment