-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAHK QuickCommand.ahk
284 lines (258 loc) · 7.72 KB
/
AHK QuickCommand.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/*
AHK QuickCommand by Azona77
requires: AutoHotkey v1.1
*/
global FunctionList := ["ActionExample","OpenAHKDoc","OpenMyComputer","OpenNotepad","OpenTaskManager","OpenControlPanel","OpenCommandPromptCMD","PasteTime"]
Loop, Read, %A_ScriptFullPath%
{
if RegExMatch(A_LoopReadLine, "^\s*(\w+)\s*\(\)\s*{", match) ; 匹配函数定义
FunctionList.Push(match1)
}
; Sort the list alphabetically
FunctionList := sortArray(FunctionList)
FunctionList := trimArray(FunctionList)
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
; Example Commands
; To Exclude: change "func(){" to "func( ){"
ActionExample(){
MsgBox, You selected Example!
}
OpenAHKDoc() {
Run, https://www.autohotkey.com/docs/v1/
}
OpenMyComputer() {
Run, explorer.exe
}
OpenNotepad() {
Run, notepad.exe
}
OpenTaskManager() {
Run, taskmgr.exe
}
OpenControlPanel() {
Run, control panel
}
OpenCommandPromptCMD() {
Run, cmd
}
PasteTime(){
FormatTime, CurrentDateTime,, yyyy-MM-dd HH_mm
Clipboard := CurrentDateTime
send, ^v
return CurrentDateTime
}
; -----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
; Main
#C::
#if GetKeyState("CapsLock", "P")
C::
SetCapsLockState, off
global LastCommand
if (A_ThisHotkey = "c" && A_ThisHotkey = A_PriorHotkey && A_TimeSincePriorHotkey < 250) && LastCommand{
gui, Destroy
%LastCommand%()
}
else if !(WinActive("AHK QuickCommand") && WinActive("ahk_class AutoHotkeyGUI")){
Gui, Destroy
FontSize := 32
Margin := FontSize * 0
backgroundColor = 1d1d1d
FontColor = d1d1d1
transparency := 240
Gui, -Caption +ToolWindow -border
Gui, Margin, %Margin%, %Margin%
Gui, Color, , %backgroundColor%
Gui, Font, s%FontSize% c%FontColor% bold, Microsoft YaHei
Gui, Add, Edit, vSearchInput w800 gUpdateListBox -vscroll -E0x200 hwndHSearchInput
if LastCommand{
SetEditCueBanner(HSearchInput, LastCommand . " ⬅️ Capslock+C+C")
}
Gui, Add, ListBox, vListBox w800 h800 gListBoxKey -E0x200,
Gui, Show,, AHK QuickCommand
WinSet, Transparent, %transparency%, AHK QuickCommand
GuiControl,, ListBox1,
for index, value in FunctionList {
GuiControl,, ListBox1, %value%
}
return
UpdateListBox:
Gui, Submit, NoHide
searchText := SearchInput
matchedList := RegExMatchList(FunctionList, searchText)
; ↓↓↓ Uncommenting following 4 lines to trigger immediately when matched item is unique
; if (IsFunc(matchedList)) {
; Gui, Destroy
; %matchedList%()
; }
GuiControl,, ListBox1,
if (matchedList != ""){
GuiControl,, ListBox1, % "|" matchedList
}
return
ListBoxKey:
GuiControlGet, selectedItem, , ListBox1
if (A_GuiEvent = "DoubleClick"){
RunListboxItem()
}
return
}
return
#if
#IfWinActive AHK QuickCommand ahk_class AutoHotkeyGUI
Space::
if !GetKeyState("Capslock", "P"){
Send, {Blind}{Space}
return
}
~Enter::
ControlGetFocus, focusedControl, A
if (focusedControl = "Edit1"){
GuiControl, Focus, ListBox
Send, {Down}
}
RunListboxItem()
return
~BackSpace::
GuiControl, Focus, Edit1
return
GetLineNumber( ){
; Code from: https://www.autohotkey.com/board/topic/954-guicontrolget-listbox-line-number/
SendMessage, 0x188, 0, 0, ListBox1, A
return (ErrorLevel+1)
}
GetLineCount( ){
; Code from: https://www.autohotkey.com/boards/viewtopic.php?t=43057
SendMessage, 0x18B, 0, 0, ListBox1, A ; LB_GETCOUNT
return ErrorLevel
}
*Esc::
if GetKeyState("Capslock", "P"){
Send, {Blind}{BackSpace}
return
}
else{
Gui, Destroy
}
Return
~LButton::
If !WinActive("AHK QuickCommand"){
Gui, Destroy
}
return
*S::
if !GetKeyState("Capslock", "P"){
Send, {Blind}s
return
}
Down::
GuiControl, Focus, ListBox
if (GetLineNumber() = GetLineCount()){
ControlSend, ListBox1, {Home}
}
else{
ControlSend, ListBox1, {Down}
}
return
*W::
if !GetKeyState("Capslock", "P"){
Send, {Blind}w
return
}
Up::
GuiControl, Focus, ListBox
if (GetLineNumber() = 0 or GetLineNumber() = 1){
ControlSend, ListBox1, {End}
}
else{
ControlSend, ListBox1, {Up}
}
return
#IfWinActive
;-----------------------------------------------------------------------------------
;-----------------------------------------------------------------------------------
RunListboxItem( ){
GuiControlGet, selectedItem, , ListBox1
if (IsFunc(selectedItem)) {
Gui, Destroy
global LastCommand
LastCommand:= selectedItem
sleep, 50
%selectedItem%()
}else{
tooltip, not existing func
GuiControl, Focus, SearchInput
sleep, 1000
tooltip
}
return
}
RegExMatchList(list, input) {
if (input = "")
return StrJoin(list, "|")
regex := StrReplace(input, " ", ".*")
; case-insensitive flag i)
regex := "i)" . regex
matched := ""
for each, item in list {
if (RegExMatch(item, regex)) {
matched .= item . "|"
}
}
return RTrim(matched, "|")
}
StrJoin(arr, delim := "|") {
result := ""
for each, item in arr
result .= item . delim
return RTrim(result, delim)
}
/*
;-----------------------------------------------------------------------------------
; Code snippet from:
; https://www.autohotkey.com/board/topic/93570-sortarray/
;-----------------------------------------------------------------------------------
*/
sortArray(arr,options="") { ; specify only "Flip" in the options to reverse otherwise unordered array items
if !IsObject(arr)
return 0
new := []
if (options="Flip") {
While (i := arr.MaxIndex()-A_Index+1)
new.Insert(arr[i])
return new
}
For each, item in arr
list .= item "`n"
list := Trim(list,"`n")
Sort, list, %options%
Loop, parse, list, `n, `r
new.Insert(A_LoopField)
return new
}
;-----------------------------------------------------------------------------------
/*
;-----------------------------------------------------------------------------------
; Code snippet from:
; https://stackoverflow.com/questions/46432447/how-do-i-remove-duplicates-from-an-autohotkey-array
;-----------------------------------------------------------------------------------
*/
trimArray(arr) { ; Hash O(n)
hash := {}, newArr := []
for e, v in arr
if (!hash.Haskey(v))
hash[(v)] := 1, newArr.push(v)
return newArr
}
;-----------------------------------------------------------------------------------
/*
;-----------------------------------------------------------------------------------
; Code snippet from:
; https://www.autohotkey.com/board/topic/76540-function-seteditcuebanner-ahk-l/
;-----------------------------------------------------------------------------------
*/
SetEditCueBanner(HWND, Cue) { ; requires AHL_L
Static EM_SETCUEBANNER := (0x1500 + 1)
Return DllCall("User32.dll\SendMessageW", "Ptr", HWND, "Uint", EM_SETCUEBANNER, "Ptr", True, "WStr", Cue)
}