-
Notifications
You must be signed in to change notification settings - Fork 8
/
hotkey_handler.ahk
310 lines (271 loc) · 6.14 KB
/
hotkey_handler.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#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.
; Read the value from the .ini file.
if FileExist("SavedVals.ini") {
MsgBox, SavedVals.ini exists.
IniRead, winId1, SavedVals.ini, SavedValsSection, winId1
IniRead, winId2, SavedVals.ini, SavedValsSection, winId2
IniRead, winId3, SavedVals.ini, SavedValsSection, winId3
IniRead, winId4, SavedVals.ini, SavedValsSection, winId4
IniRead, winId5, SavedVals.ini, SavedValsSection, winId5
IniRead, winId6windows, SavedVals.ini, SavedValsSection, winId6windows
IniRead, winId7gitlab, SavedVals.ini, SavedValsSection, winId7gitlab
IniRead, winId8, SavedVals.ini, SavedValsSection, winId8
IniRead, winId9Git, SavedVals.ini, SavedValsSection, winId9Git
IniRead, winId10, SavedVals.ini, SavedValsSection, winId10
} else {
winId1 = 0
winId2 = 0
winId3 = 0
winId4 = 0
winId5 = 0
winId6windows = 0
winId7gitlab = 0
winId8 = 0
winId9Git = 0
winId10 = 0
}
; Set it to run code when the script ends, such as shutdown, clicking exit from the tray icon, reloading, etc.
OnExit, ExitProgram
DetectHiddenWindows, On
; Swipe horizontal
^!+1:: ; Ctrl+Alt+shift+1
{
WinActivate ahk_id %winId9Git%
Send git diff{Enter}
return
}
; Swipe vertical
^!+2:: ; Ctrl+Alt+shift+2
{
WinActivate ahk_id %winId9Git%
Send git log{Enter}
return
}
; Swipe Arrow down
^!+3:: ; Ctrl+Alt+shift+3
{
WinActivate ahk_id %winId9Git%
Send git fetch && git pull origin $(git rev-parse --abbrev-ref HEAD){Enter}
return
}
; Swipe 'C' as in COM Ports
^!+4:: ; Ctrl+Alt+shift+4
{
listComPorts()
return
}
; Swipe Arrow Right
^!+5:: ; Ctrl+Alt+shift+5
{
send {Media_Next}
return
}
; Swipe Arrow Up
^!+6:: ; Ctrl+Alt+shift+6
{
WinActivate ahk_id %winId9Git%
Send git push origin $(git rev-parse --abbrev-ref HEAD)
return
}
; Swipe S
^!+7:: ; Ctrl+Alt+shift+7
{
WinActivate ahk_id %winId9Git%
Send git status{Enter}
return
}
openIfMinimizedHideIfOpen(winid)
{
WinGet, activeWin ,, A
if (winid == activeWin)
{
WinMinimize ahk_id %winid%
}
else
{
WinActivate ahk_id %winid%
}
return
}
listComPorts()
{
COMPort := Object()
COMPortName := Object()
Num:=0
Array := []
Loop, HKLM, HARDWARE\DEVICEMAP\SERIALCOMM\
{
RegRead, OutputVar
COMPort%Num%:=OutputVar
COM_result:=COMPort%Num%
Loop, HKLM, SYSTEM\CurrentControlSet\Enum, 1, 1
{
if (A_LoopRegName = "FriendlyName")
{
RegRead, Outputvar
IfInString,Outputvar,%COM_result%
{
;MsgBox %COM_result%
If InStr(COM_result, "COM")
{
Array.Push(COM_result)
}
}
}
}
}
res := ""
for index, element in Array
{
res .= element
res .= "`n"
}
;MsgBox %res%
TrayTip , , %res%, 5, (16 + 32)
}
^!a:: ; Ctrl+Alt+a
{
openIfMinimizedHideIfOpen(winId1)
return
}
^!b:: ; Ctrl+Alt+b
{
openIfMinimizedHideIfOpen(winId2)
return
}
^!c:: ; Ctrl+Alt+c
{
openIfMinimizedHideIfOpen(winId3)
return
}
^!d:: ; Ctrl+Alt+d
{
openIfMinimizedHideIfOpen(winId4)
return
}
^!e:: ; Ctrl+Alt+e
{
openIfMinimizedHideIfOpen(winId5)
return
}
^!f:: ; Ctrl+Alt+f
{
Send #{tab} ;Win + tab (show all windows)
;openIfMinimizedHideIfOpen(winId6windows)
return
}
^!g:: ; Ctrl+Alt+g
{
Run, chrome.exe "https://git-sho-mlm.u-blox.net/" " --new-window "
;openIfMinimizedHideIfOpen(winId7gitlab)
return
}
^!h:: ; Ctrl+Alt+h
{
openIfMinimizedHideIfOpen(winId8)
return
}
^!i:: ; Ctrl+Alt+i
{
openIfMinimizedHideIfOpen(winId9Git)
return
}
^!j:: ; Ctrl+Alt+j
{
openIfMinimizedHideIfOpen(winId10)
return
}
; Config shortcuts
; Shortcut ^!a is configured by ^!f
; Shortcut ^!b is configured by ^!g
; etc.
; So to set the window connected to ^!a you will send ^!f
; and whatever window in focus will be connected to ^!a.
^!k:: ; Ctrl+Alt+k
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId1 = %winid%
return
}
^!l:: ; Ctrl+Alt+l
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId2 = %winid%
return
}
^!m:: ; Ctrl+Alt+m
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId3 = %winid%
return
}
^!n:: ; Ctrl+Alt+n
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId4 = %winid%
return
}
^!o:: ; Ctrl+Alt+o
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId5 = %winid%
return
}
^!p:: ; Ctrl+Alt+p
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId6windows = %winid%
return
}
^!q:: ; Ctrl+Alt+q
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId7gitlab = %winid%
return
}
^!r:: ; Ctrl+Alt+r
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId8 = %winid%
return
}
^!s:: ; Ctrl+Alt+s
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId9Git = %winid%
return
}
^!t:: ; Ctrl+Alt+t
{
SoundBeep, 150, 250
WinGet, winid ,, A ;
winId10 = %winid%
return
}
; return so that ExitProgram is not executed now
return
; The code to run when it exits.
ExitProgram:
IniWrite, %winId1%, SavedVals.ini, SavedValsSection, winId1
IniWrite, %winId2%, SavedVals.ini, SavedValsSection, winId2
IniWrite, %winId3%, SavedVals.ini, SavedValsSection, winId3
IniWrite, %winId4%, SavedVals.ini, SavedValsSection, winId4
IniWrite, %winId5%, SavedVals.ini, SavedValsSection, winId5
IniWrite, %winId6windows%, SavedVals.ini, SavedValsSection, winId6windows
IniWrite, %winId7gitlab%, SavedVals.ini, SavedValsSection, winId7gitlab
IniWrite, %winId8%, SavedVals.ini, SavedValsSection, winId8
IniWrite, %winId9Git%, SavedVals.ini, SavedValsSection, winId9Git
IniWrite, %winId10%, SavedVals.ini, SavedValsSection, winId10
ExitApp