Skip to content

Instantly share code, notes, and snippets.

@sam159247
Last active August 14, 2020 10:43
Show Gist options
  • Save sam159247/5b4f34f848eb4f9b0303606289b56954 to your computer and use it in GitHub Desktop.
Save sam159247/5b4f34f848eb4f9b0303606289b56954 to your computer and use it in GitHub Desktop.
One key to change input source with AutoHotkey
#SingleInstance Force
*~LShift::Send {Blind}{vk07}
*~LAlt::Send {Blind}{vk07}
*~RAlt::Send {Blind}{vk07}
LShift::
Send {Shift Down}
return
LShift Up::
Send {Shift Up}
SetDefaultKeyboard(0x0409) ;; 切換為英文輸入
return
LAlt up::
SetDefaultKeyboard(0x0404) ;; 切換為注音輸入
return
RAlt up::
SetDefaultKeyboard(0x0411) ;; 切換為日文輸入
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%
}
}