-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAlt.ahk
78 lines (73 loc) · 2.43 KB
/
RAlt.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
;------------------------------------------------------------
; RAlt段开始
;------------------------------------------------------------
DetectAltKey() { ; 检测按键函数
global AltHotKeyIsInput
If !GetKeyState("RAlt", "P")
Return
Input, InputKey, IL1 ; 检测单个按键输入并保存到InputKey变量中
If (ErrorLevel = "NewInput"){
If !GetKeyState("RAlt", "P")
Return
Else If (AltHotKeyIsInput = 0)
SendStr(InputKey)
} Else If (ErrorLevel = "Max") {
SendStr(InputKey)
}
DetectAltKey() ; 递归调用自身
}
SendStr(InputStr) { ; 发送原样字符函数
global AltAnotherKeyIsInput
AltAnotherKeyIsInput := 1 ; 置空变量,防止执行If下的语句
SendInput, % Format("{U+{1:#x}}", Ord(InputStr))
}
Swtich_IME(NewState) { ; 切换输入法函数,-1为切换
PtrSize := !A_PtrSize ? 4 : A_PtrSize
VarSetCapacity(StGTI, CbSize := (PtrSize*6)+24, 0)
NumPut(CbSize, StGTI, 0, "UInt")
DllCall("GetGUIThreadInfo", "UInt", 0, "UInt", &StGTI)
HWND := NumGet(StGTI, 8+PtrSize, "UInt")
If (NewState = -1) {
PreviousState := DllCall("SendMessage"
, "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", HWND)
, "UInt", 0x0283
, "Int", 0x0005
, "Int", 0)
Return DllCall("SendMessage"
, "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", HWND)
, "UInt", 0x0283
, "Int", 0x006
, "Int", !PreviousState)
} Else {
Return DllCall("SendMessage"
, "UInt", DllCall("imm32\ImmGetDefaultIMEWnd", "UInt", HWND)
, "UInt", 0x0283
, "Int", 0x006
, "Int", NewState)
}
}
*RAlt::
AltAnotherKeyIsInput := 0
AltHotKeyIsInput := 0
SendInput, {RAlt Up}
DetectAltKey()
Return
RAlt Up::
Input ; 终止函数中还在等待输入的Input
If !AltAnotherKeyIsInput ; 表示按下了RAlt键,且中途没有按下其他按键
Swtich_IME(-1) ; 切换输入法
AltAnotherKeyIsInput := 0
AltHotKeyIsInput := 0
Return
#If GetKeyState("RAlt", "P")
; Intellij IDEA窗口激活时,RAlt + Enter = Ctrl + Shift + Enter
Enter::
Input ; 终止函数中还在等待输入的Input
SendInput, ^+{Enter}
AltAnotherKeyIsInput := 1
AltHotKeyIsInput := 1
Return
#If
;------------------------------------------------------------
; RAlt段结束
;------------------------------------------------------------