Last active
August 14, 2020 10:43
-
-
Save sam159247/5b4f34f848eb4f9b0303606289b56954 to your computer and use it in GitHub Desktop.
One key to change input source with AutoHotkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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% | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference
http://jdev.tw/blog/5738/autohotkey-set-default-keyboard
https://github.com/karakaram/alt-ime-ahk
https://www.autoitscript.com/forum/topic/189527-change-the-keyboard-language-in-custom-window/