Last active
February 12, 2025 14:04
-
-
Save maokwen/4d99f5c0aa2e7c0c114c708b03fb73ae to your computer and use it in GitHub Desktop.
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
#Include %A_ScriptDir% | |
timeInterval := 500 | |
; +-------------------------+-------------------------+ | |
; | SubLanguage ID | Primary Language ID | | |
; +-------------------------+-------------------------+ | |
; 15 10 9 0 bit | |
InChs() { | |
ime_status := DllCall("GetKeyboardLayout", "int", 0, "UInt") | |
return (ime_status & 0xffff) = 0x804 ; LANGID(Chinese) = 0x804 | |
} | |
SwitchImeState(id) { | |
SendMessage(0x283, ; WM_IME_CONTROL | |
0x002, ; wParam IMC_SETCONVERSIONMODE | |
1025, ; lParam (Chinese) | |
, ; Control (Window) | |
id) | |
} | |
DetectHiddenWindows True | |
SetTimer Mainloop, 1000 | |
MainLoop() { | |
try { | |
hWnd := WinGetID("A") | |
id := DllCall("imm32\ImmGetDefaultIMEWnd", "Uint", hWnd, "Uint") | |
if (InChs()) { | |
SwitchImeState(id) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
您好,您编写的脚本非常好用,但在使用时我发现了个问题:
脚本中使用的Sleep函数的实现方式可能是阻塞线程,在使用sleep时脚本的CPU占用率会达到3%,我使用SetTimer修改了循环的实现方式,现在CPU占用率显示为0%。
下面是简单的修改(原文件25行之后):