-
Notifications
You must be signed in to change notification settings - Fork 2
/
im-select-cn.ahk
91 lines (79 loc) · 2.86 KB
/
im-select-cn.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; 获取命令行参数的数量
ArgCount := A_Args.Count()
if (ArgCount > 1) {
MsgBox 命令行参数最多一个, 1为中文, 0为英文, 2为直接切换
ExitApp, 1
}
; 当前输入法状态
current_IME := IME_GET()
; 由于vscode的vim插件好像会执行一次不带参数的情况, 总是弹出消息框, 所以注释掉
; 打印当前输入法状态
; if (ArgCount == 0){
; MsgBox 命令行参数最多一个, 1为中文, 0为英文, 2为直接切换. 当前输入法状态为: %current_IME%
; ExitApp, 0
; }
; 命令行参数的第一个参数下标为1
expect_IME := A_Args[1]
if (expect_IME != current_IME){
if (expect_IME == 2) {
if (current_IME == 1){
expect_IME = 0
}else{
expect_IME = 1
}
}
; 也可以简单模拟按下shift切换输入法状态
; Send {Shift}
IME_SET(expect_IME)
}
; 获取输入法的中英文状态
IME_GET(WinTitle="")
;-----------------------------------------------------------
; IMEの状態の取得
; 対象: AHK v1.0.34以降
; WinTitle : 対象Window (省略時:アクティブウィンドウ)
; 戻り値 1:ON 0:OFF
;-----------------------------------------------------------
{
ifEqual WinTitle,, SetEnv,WinTitle,A
WinGet,hWnd,ID,%WinTitle%
DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
;Message : WM_IME_CONTROL wParam:IMC_GETOPENSTATUS
DetectSave := A_DetectHiddenWindows
DetectHiddenWindows,ON
SendMessage 0x283, 0x005,0,,ahk_id %DefaultIMEWnd%
DetectHiddenWindows,%DetectSave%
Return ErrorLevel
}
; 设置输入法的中英文状态
IME_SET(setSts, WinTitle="")
;-----------------------------------------------------------
; IMEの状態をセット
; 対象: AHK v1.0.34以降
; SetSts : 1:ON 0:OFF
; WinTitle: 対象Window (省略時:アクティブウィンドウ)
; 戻り値 1:ON 0:OFF
;-----------------------------------------------------------
{
ifEqual WinTitle,, SetEnv,WinTitle,A
WinGet,hWnd,ID,%WinTitle%
DefaultIMEWnd := DllCall("imm32\ImmGetDefaultIMEWnd", Uint,hWnd, Uint)
;Message : WM_IME_CONTROL wParam:IMC_SETOPENSTATUS
DetectSave := A_DetectHiddenWindows
DetectHiddenWindows,ON
SendMessage 0x283, 0x006,setSts,,ahk_id %DefaultIMEWnd%
DetectHiddenWindows,%DetectSave%
Return ErrorLevel
}
; 可以设置按键来调试, 如下, 按下a键, 弹出MsgBox消息框, 且在鼠标位置显示文本(ToolTip)
; a::
; xxx := IME_GET()
; MsgBox, 输入法状态 1中文 0英文: %xxx%
; ToolTip,英文
; Sleep,1000
; ToolTip
; Return