forked from kayone/rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocket.ahk
419 lines (313 loc) · 5.98 KB
/
rocket.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#NoEnv
#SingleInstance force
SetCapsLockState, Off
SetControlDelay, 0
Setworkingdir %A_ScriptDir%
WinGet, winId, ID, A
WinGetTitle, title, A
WinGet, pname , ProcessName, %title%
StringLower, pname , pname
OutputDebug, Starting
str =: pName
command= ERROR
badInputMessage := "$&*&%$#T&^$#@$#%????"
IniRead, browserPath, settings.ini, settings , browser
if(browserPath = ERROR)
{
MsgBox "Browser has not been configured"
exit()
}
showUi:
{
iniWidth := 500 ;initial width of gui
guiWidth := iniWidth + 13*2 ; 13 is the unreduceable left-margin spacing between gui and text
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, 00A9DA
Gui, Font, s11, Consolas ;Set a large font size (32-point).
Gui, Add, Text, vMyText cBlack w%iniWidth% left, ;can put LEFT, CENTER, or RIGHT for text alignment
Winset, Transparent, 243
Gui, Show, y-50 ;show window off-screenl
WinGetPos,,,,height, A ;store GUI height (last parameter is the gui's title)
Y := -height
Gui, Show, xCenter y%Y% w%guiWidth%, %A_ScriptFullPath% ;position GUI just above top border
increment := 5
while Y < -increment ;increment gui into position
{
Y := Y + increment
Gui, Show, y%Y%
sleep 5
}
Gui, Show, y0 NoActivate
setText(pName)
}
readChar() ;input a character and show it on the GUI
setText(text)
{
global
str:= text
GuiControl,, MyText, %text%
return
}
getCommand()
{
global
OutputDebug, Parsing Command
if (command = ERROR || InStr(str ,">") = 0)
{
IniRead, command, settings.ini, commands, %str%
if(InStr(str ,"ERROR") = 0)
{
IfExist, extentions\%str%.ahk
command:=str
}
}
OutputDebug, Command -> %command%
return command
}
getInput(input)
{
global
OutputDebug, parsing input
currentCommand := GetCommand()
if currentCommand = ERROR
{
return %str%
}
seperator := InStr(str ,">")
;check if the user has provided any args or just the command
if(seperator = 0)
{
return ""
}
userInput := Trim(SubStr(str, seperator + 1), A_Space)
OutputDebug, Input -> %userInput%
return userInput
}
format()
{
global
OutputDebug, re-formating
command := GetCommand()
if command = ERROR ; if still error
{
badInput()
}
else
{
str := command . "> "
setText(str)
}
}
evaluate()
{
OutputDebug, evaluating input -> %str%
attemptCommand()
attemptShortCut()
attemptExtention()
badInput()
}
attemptCommand()
{
global
command := GetCommand()
if command != ERROR
{
OutputDebug, command %command% detected
IniRead, template, settings.ini, templates, %command%
OutputDebug, command teamplate %template%
if template != ERROR
{
userInput := getInput(str)
placeHolder := "[lookup]"
StringReplace, formattedCommand, template, %placeHolder% , %userInput%
launch(formattedCommand) ;quotes are used incase the input has spaces, so it is not treated as more than one parameter
}
}
}
attemptShortcut()
{
global
OutputDebug, hotkey detected
IniRead, hkey, settings.ini, hkey_%pname%, %str%
if hkey = ERROR
{
IniRead, hkey, settings.ini, hkey_global, %str%
}
if hkey != ERROR
{
WinActivate, ahk_id %winId%
SendInput %hkey%
GetKeyState, shiftState, Shift
GetKeyState, ctrlState, Ctrl
GetKeyState, altState, Alt
if shiftState = D
{
SendInput {shift up}
}
if ctrlState = D
{
SendInput {ctrl up}
}
if altState = D
{
SendInput {alt up}
}
exit()
}
}
attemptExtention()
{
global
extention := getCommand()
userInput := getInput(str)
IfExist, extentions\%extention%.ahk
{
run, extentions\%extention%.ahk "%userInput%" "%pname%" "%winId%" "%browserPath%"
exit()
}
}
backspace()
{
global
StringTrimRight, str, str, 1 ;remove a character from the right side of %str%
setText(str)
}
exit()
{
global
SetCapsLockState, Off
Y := 0
while Y > (0-height)
{
Y := Y - 3
Gui, Show, y%Y% NoActivate
sleep 10
}
exitApp
}
badInput()
{
global
OutputDebug, Bad Input
setText(badInputMessage)
sleep 1000
readChar()
}
readChar()
{
global
setText(pName)
command := Error
Loop
{
Input, char, L1 M, {enter}{backspace} ;input a single character in %char%
processKeyPress(char)
}
}
processKeyPress(char)
{
global
asciiCode := Asc(char)
;MsgBox %char% : %asciiCode% : %ErrorLevel%
if asciiCode = 0 ;check if user has pressed a terminating key
{
if InStr(ErrorLevel, "Backspace")
{
backspace()
return
}
evaluate()
return
}
;ctrl+v;
if(asciiCode == 22)
{
appendText(clipboard)
return
}
;ctrl+c
if(asciiCode == 3)
{
clipboard:= str
return
}
;ctrl+x
if(asciiCode == 24)
{
clipboard:= str
setText("")
return
}
if(!InStr(str ,">") && (asciiCode == 9 || char == A_Space))
{
format()
}
else if(asciiCode > 31) ;don't print none-readable charecter.
{
appendText(char)
}
}
appendText(char)
{
global
if(str == pName)
{
setText("")
}
str := str . char
setText(str)
}
launch(path)
{
OutputDebug, Launching %path%
if(InStr(path, "http://", false, 1) || InStr(path, "https://", false, 1))
{
launchUrl(path)
}
else
{
run, %path%
}
exit()
}
launchUrl(url)
{
global
encodedUrl := EncodeURL(url)
run, %browserPath% %encodedUrl%
}
EncodeURL(p_data)
{
old_FormatInteger := A_FormatInteger
SetFormat, Integer, hex
unsafe =
( Join LTrim
25000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20
22233C3E5B5C5D5E607B7C7D7F808182838485868788898A8B8C8D8E8F9091929394
95969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6
B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8
D9DADBDCDDDEDF7EE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9
FAFBFCFDFEFF
)
loop, % StrLen( unsafe )//2
{
StringMid, token, unsafe, A_Index*2-1, 2
StringReplace, p_data, p_data, % Chr( "0x" token ), `%%token%, all
}
SetFormat, Integer, %old_FormatInteger%
return, p_data
}
;~LButton::
;~RButton::
~Home::
~End::
~PgUp::
~PgDn::
~Alt::
~LWin::
~RWin::
~Esc::
CapsLock::
{
exit()
}