-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXclip.au3
More file actions
421 lines (375 loc) · 11.2 KB
/
Xclip.au3
File metadata and controls
421 lines (375 loc) · 11.2 KB
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
420
#cs ----------------------------------------------------------------------------
Author:Drew Royster
Script Function:
Toggle list of commonly typed items. Clicking on button copies to clipboard
#ce ----------------------------------------------------------------------------
;
#include <INet.au3>
#include <Misc.au3>
#include <GuiButton.au3>
#include <GuiToolBar.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
;NOTE:change to work dynamically with different resolutions
Global $HEIGHT = 332
Global $WIDTH = 117
Global $BUTTON_SPACER = 32
Global $BUTTON_HEIGHT = 25
Global $BUTTON_WIDTH = 99
Global $FULLDESKTOPWIDTH = _WinAPI_GetSystemMetrics(78)
HotKeySet("{END}", "END")
HotKeySet("{INS}","Index")
Global $MARGIN = 8
Global $Active = WinGetTitle("")
$name = ""
$data = ""
;get mouse position
$pos = MouseGetPos()
;if text is highlighted will add to file
;InitAdd()
;check if file exists creates file if one doesn't exist
If FileExists(@ScriptDir & "/index.txt")=0 Then
_FileCreate(@ScriptDir & "/index.txt")
EndIf
;reads data to file
ReadFile()
;parse data
Parse()
;create initial gui
CreateGui()
;loop until button pressed
While 1
If WinActive("Xclip") = 0 Then ExitLoop
$msg = GUIGetMsg()
$leftClick = False
Switch $msg
Case $BUTTON[0] To $BUTTON[$SIZE-1]
GUIDelete($popUp)
WinActivate($Active)
Do
Sleep(1)
Until _IsPressed("01")
;slight delay helps enter text correctly when clicking into browser url(browser has slight delay to respond)
Sleep(250)
Send($DATA[$msg-3])
ExitLoop
Case $BUTTON[$FULL_SIZE-1]
GUICtrlSetData($BUTTON[$FULL_SIZE-1], "DONE")
While 1
$msg = GUIGetMsg()
Switch $msg
Case $BUTTON[0] To $BUTTON[$SIZE-1]
_ArrayDelete($FULL, $msg-3)
GUICtrlSetData($BUTTON[$msg-3], "DELETED")
Case $BUTTON[$FULL_SIZE-1]
GUIDelete()
SyncFile()
Parse()
CreateGui()
ExitLoop
EndSwitch
WEnd
Case $BUTTON[$FULL_SIZE-2]
;do nothing for now add button
GUIDelete()
prompt()
If ValidateInput($name) Or ValidateInput($data) Then
$full_string = $name & "`" & $data
_ArrayAdd($FULL, $full_string)
SyncFile()
Parse()
CreateGui()
Else
CreateGui()
EndIf
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Exit
Func SyncFile()
FileDelete(@ScriptDir & "\index.txt")
_FileCreate(@ScriptDir & "\index.txt")
_FileWriteFromArray(@ScriptDir & "\index.txt", $FULL)
$SIZE = UBound($FULL)
If $SIZE<1 Then
prompt()
If ValidateInput($name) And ValidateInput($data) Then
$full_string = $name & "`" & $data
Global $FULL[1]
$FULL[0]=$full_string
$SIZE=$SIZE+1
Else
Exit
EndIf
EndIf
$FULL_SIZE = $SIZE+2
EndFunc
;deletes gui and closes script
Func End()
GUIDelete($popUp)
Exit
EndFunc
Func Index()
GUIDelete($popUp)
Run("notepad index.txt", @ScriptDir)
Exit
EndFunc
;sets gui x position to prevent gui appearing off the screen
Func GuiXPos()
If $pos[0] <= ($GWidth/2) Then
Return 0
ElseIf $pos[0] >= ($FULLDESKTOPWIDTH-($GWidth/2)) Then
Return ($FULLDESKTOPWIDTH-$GWidth)
Else
Return $pos[0] - ($GWidth/2)
EndIf
EndFunc
;sets gui y position to prevent gui appearing off the screen
Func GuiYPos()
If $pos[1] <= ($HEIGHT/2) Then
Return 0
ElseIf $pos[1] >= (@DesktopHeight-($HEIGHT/2)) Then
Return (@DesktopHeight-$HEIGHT)
Else
Return ($pos[1]-($HEIGHT/2))
EndIf
EndFunc
;determines which monitor to display input box On
Func GuiInputXPos()
If $pos[0] > @DesktopWidth Then
Return $FULLDESKTOPWIDTH-(@DesktopWidth/2)
Else
Return (@DesktopWidth/2)
EndIf
EndFunc
;parses the data
Func Parse()
Global $BUTTON_NAME[$SIZE]
_ArrayAdd($BUTTON_NAME,"ADD")
_ArrayAdd($BUTTON_NAME,"DELETE")
Global $DATA[$SIZE]
Local $i = 0
Do
$tmp = StringSplit($FULL[$i],"`")
If @error = 1 Then MsgBox(1, "error", "Use (`) as delimeter to separate name from value" & @LF & "No empty lines allowed")
$BUTTON_NAME[$i] = $tmp[1]
$DATA[$i] = $tmp[2]
$i = ($i+1)
Until $i>($SIZE-1)
EndFunc
;determine gui width
Func GWidth()
Select
Case $SIZE<=8
Return $WIDTH
Case $SIZE<=18
Return $WIDTH*2
Case $SIZE<=28
Return $WIDTH*3
Case $SIZE<=38
Return $WIDTH*4
EndSelect
EndFunc
;determine gui height
Func GHeight()
If $SIZE<=8 Then
Return ((($FULL_SIZE)*$BUTTON_SPACER)+$MARGIN)
Else
Return $HEIGHT
EndIf
EndFunc
;not being used on current build possible add later on
Func InitAdd()
;if text is highlighted it will copy
ClipPut("")
Send("^c")
$text = ClipGet()
;Read from text file
;init index
If StringCompare($text, "") = 0 Then
;do nothing
Else
;write last value to index.txt
$name = InputBox("Name", "Enter the name for the copied value", "", "", 220, 120, $pos[0], $pos[1])
If @error = 1 Then
Exit
EndIf
;removes new lines to prevent error
$cleanText = StringRegExpReplace($text, "\r\n|\r|\n", " ")
$delimetedText = @CRLF & $name & "`" & $cleanText
FileWrite(@ScriptDir & "\index.txt",$delimetedText)
EndIf
EndFunc
;reads file and declares $SIZE and $FULL_SIZE
Func ReadFile()
Global $FULL = FileReadToArray(@ScriptDir &"\index.txt")
If @error Then
prompt()
If ValidateInput($name) And ValidateInput($data) Then
$full_string = $name & "`" & $data
Global $FULL[1]
$FULL[0]=$full_string
_FileWriteFromArray(@ScriptDir & "\index.txt", $FULL)
Else
Exit
EndIf
EndIf
;data size
Global $SIZE = UBound($FULL)
Global $FULL_SIZE = $SIZE+2
EndFunc
;checks if data from input box is valid
Func ValidateInput($string)
If StringCompare($string, "Name of popup button") = 0 Or StringCompare($string, "Value behind popup button") = 0 Or StringCompare($string, "") = 0 Then
Return False
Else
Return True
EndIf
EndFunc
#cs
*This function will create a gui depending on the size of the array adding the delete and add buttons to the end of it
#ce
Func CreateGui()
;call GWidth func to get the gui's width
Global $GWidth = GWidth()
Global $GHeight = GHeight()
Select
;Create GUi
Case $FULL_SIZE<=10
$spacer = $MARGIN
Global $popUp = GUICreate("Xclip", $GWidth, $GHeight, GuiXPos(), GuiYPos(), $WS_POPUP, $WS_EX_TOPMOST)
;array of buttons
Global $BUTTON[$FULL_SIZE]
;loop to place and name buttons
For $i = 0 to ($FULL_SIZE-1)
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], $MARGIN, $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
;handles up to 18 values
Case $FULL_SIZE <= 20
Global $popUp = GUICreate("Xclip", $GWidth, $GHeight, GuiXPos(), GuiYPos(), $WS_POPUP, $WS_EX_TOPMOST)
$spacer = 8
;array of buttons
Global $BUTTON[$FULL_SIZE]
;loop to place and name buttons
For $i = 0 to 9
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], $MARGIN, $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer+32
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 10 to ($FULL_SIZE-1)
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+$WIDTH), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
;handles up to 28 values
Case $FULL_SIZE <= 30
Global $popUp = GUICreate("Xclip", $GWidth, $GHeight, GuiXPos(), GuiYPos(), $WS_POPUP, $WS_EX_TOPMOST)
$spacer = 8
;array of buttons
Global $BUTTON[$FULL_SIZE]
;loop to place and name buttons
For $i = 0 to 9
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], $MARGIN, $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 10 to 19
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+$WIDTH), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 20 to ($FULL_SIZE-1)
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+($WIDTH*2)), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
;handles up to 38 values
Case $FULL_SIZE <= 40
Global $popUp = GUICreate("Xclip", $GWidth, $GHeight, GuiXPos(), GuiYPos(), $WS_POPUP, $WS_EX_TOPMOST)
$spacer = 8
;array of buttons
Global $BUTTON[$FULL_SIZE]
;loop to place and name buttons
For $i = 0 to 9
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], $MARGIN, $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 10 to 19
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+$WIDTH), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 20 to 29
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+($WIDTH*2)), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer + $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
$spacer = 8
For $i = 30 to $FULL_SIZE-1
$BUTTON[$i] = GUICtrlCreateButton($BUTTON_NAME[$i], ($MARGIN+($WIDTH*3)), $spacer, $BUTTON_WIDTH, $BUTTON_HEIGHT)
$spacer = $spacer+ $BUTTON_SPACER
GUICtrlSetFont($BUTTON[$i], 11, 700, "Aharoni")
Next
;tells user of error if more than 38 items are added
Case Else
MsgBox(1,"Error","Xclip only supports up to 38 items")
Exit
EndSelect
;sets background color
GUISetBkColor(0x808080)
;Sets Add Button to
GUICtrlSetFont($BUTTON[$FULL_SIZE-2], 12, 700, "Aharoni")
GUICtrlSetColor($BUTTON[$FULL_SIZE-2], 0x228b22)
;Sets Delete Button Color to Red
GUICtrlSetFont($BUTTON[$FULL_SIZE-1], 12, 700, "Aharoni")
GUICtrlSetColor($BUTTON[$FULL_SIZE-1], 0xff0000)
;show gui
GUISetState(@SW_SHOWNORMAL, $popUp)
;set transparency
WinSetTrans($popUp, "", 200)
;rounds corners
;_GuiRoundCorners($popUp,0,0,20,20)
EndFunc
; Round corners function NOT USED CURRENTLY
Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
Local $XS_pos, $XS_ret, $XS_ret2
$XS_pos = WinGetPos($h_win)
$XS_ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $XS_pos[2], "long", $XS_pos[3], "long", $i_x3, "long", $i_y3)
If $XS_ret[0]Then
$XS_ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $XS_ret[0], "int", 1)
EndIf
EndFunc ;==>_GuiRoundCorners
;prompt simply prompts for a name and value for a new item
Func prompt()
GUICreate("New Item",140,135, GuiInputXPos()-110)
GUICtrlCreateLabel("Enter Button Name",5,5,120,20)
$handle_name=GUICtrlCreateEdit("e.g. IP address",5,25,120,20)
GUICtrlCreateLabel("Enter associated value",5,45,120,20)
$handle_data=GUICtrlCreateEdit("e.g. 10.204.128.100",5,65,120,20)
$submit=GUICtrlCreateButton("SUBMIT",5,90,120,30)
GUISetState()
While(1)
$msg=GUIGetMsg()
Switch $msg
Case $submit
$name=GUICtrlRead($handle_name)
$data=GUICtrlRead($handle_data)
GUIDelete()
ExitLoop
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
EndFunc