forked from camerb/AHKs
-
Notifications
You must be signed in to change notification settings - Fork 38
/
FcnLib-Clipboard.ahk
200 lines (171 loc) · 4.32 KB
/
FcnLib-Clipboard.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
;#include FcnLib.ahk
;FcnLib-Clipboard.ahk by camerb
;This library contains a bunch of functions that make using the clipboard easier and more reliable
;NOTE that this should not wait at the end...
copy(options="")
{
;this seems super stupid... why would i do all this junk?
;0 ""
;10 "cautious"
;100 "slow"
;500 "super slow"
;1000 "super super slow"
sleepTime:=10
if InStr(options, "fast")
sleepTime:=10
else if InStr(options, "noSleep")
sleepTime:=0
else if InStr(options, "slow")
sleepTime:=100
Send, {CTRL DOWN}
Sleep, %sleepTime%
Send, c
Sleep, %sleepTime%
Send, {CTRL UP}
Sleep, %sleepTime%
Send, ^c
}
;TODO you need to paste in a ghetto way for the cmd prompt
paste(options="")
{
sleepTime:=10
if InStr(options, "fast")
sleepTime:=10
else if InStr(options, "noSleep")
sleepTime:=0
else if InStr(options, "slow")
sleepTime:=100
Send, {CTRL DOWN}
Sleep, %sleepTime%
Send, v
Sleep, %sleepTime%
Send, {CTRL UP}
}
CopyWait2(options="useNull")
{
knownClipboard:="null"
if InStr(options, "useBlank")
knownClipboard:=""
Clipboard:=knownClipboard
ClipWait(knownClipboard)
Sleep, 10
copy()
;Send, {CTRLDOWN}c{CTRLUP}
Sleep, 10
ClipWaitNot(knownClipboard)
returned:=Clipboard
return returned
}
CopyWait(options="useNull")
{
knownClipboard:="null"
if InStr(options, "useBlank")
knownClipboard:=""
Clipboard:=knownClipboard
ClipWait(knownClipboard)
Sleep, 10
copy()
;Send, {CTRLDOWN}c{CTRLUP}
Sleep, 10
ClipWaitNot(knownClipboard)
returned:=Clipboard
return returned
}
/*
CopyWait2()
{
Clipboard:=""
ClipWait("")
ss()
copy()
;Send, {CTRLDOWN}c{CTRLUP}
ss()
ClipWaitNot("")
returned:=Clipboard
return returned
}
*/
/*
;this is what I've got at the moment... it needs to be refined
CopyWait(options="")
{
null := "null"
Clipboard := null
iniPP("before ClipWait(null)")
ClipWait(null)
iniPP("after ClipWait(null)")
copy(options)
iniPP("before wait for clip contents")
;ClipWaitNot(null)
Loop 30
{
count++
if (Clipboard != null)
{
if (count >= 2)
iniPP("clipboard no longer null after # of tries: " . count)
;debug("silent log yellow line", "clipboard is no longer null after # of tries:", count)
break
}
copy()
Sleep, 10
}
iniPP("after wait for clip contents")
return Clipboard
;number to verify that the clipboard was never assigned to
;null:=Random(100000,999999)
;Clipboard:=null
;Sleep, 100
;copy()
;count=0
;Loop
;{
;count++
;if (Clipboard != null)
;{
;;if (count >= 2)
;;debug("silent log yellow line", "clipboard is no longer null after # of tries:", count)
;break
;}
;Sleep, 100
;}
;TODO return false if error?
}
*/
;TODO options (like a timeout)
;TODO options "notEqual" (then condense the ClipWait and ClipWaitNot into one
;Waits for the clipboard to contain a specified string (exact match)
ClipWait(clipboardContentsToWaitFor, options="")
{
Loop 10
{
ClipboardContents := Clipboard
if (ClipboardContents == clipboardContentsToWaitFor)
break
Sleep, 10
}
}
ClipWaitNot(clipboardContentsToWaitFor, options="")
{
Loop 10
{
ClipboardContents := Clipboard
if (ClipboardContents != clipboardContentsToWaitFor)
break
Sleep, 10
}
}
;This is kinda similar to the Send or SendInput methods, except that it uses the clipboard to send text
SendViaClip(text)
{
;hey wait... we know what we want to put on the clipboard, so just check if that is equal
knownClipboard:=""
Clipboard:=knownClipboard
ClipWait(knownClipboard)
Clipboard:=text
ClipWaitNot(knownClipboard)
paste()
}
;TODO ClipWaitNull(), ClipWaitNotNull()
; maybe waiting for it to be empty is the best solution... who would ever copy nothing? answer: me, when I am trying to scan through empty cells in Mel's ASE macro
; then again, there are probably some times when we want to wait for it to contain the text "null"