/
Clip.ahk
47 lines (46 loc) · 1.28 KB
/
Clip.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
/** get clipboard content
*/
Clip_Get(){
return %clipboard%
}
/** set clipboard content
*/
Clip_Set($content:=""){
Clipboard = %$content%
}
Clip(Text="", Reselect="") ; http://www.autohotkey.com/forum/viewtopic.php?p=467710 , modified February 19, 2013
{
Static BackUpClip, Stored, LastClip
If (A_ThisLabel = A_ThisFunc) {
If (Clipboard == LastClip)
Clipboard := BackUpClip
BackUpClip := LastClip := Stored := ""
} Else {
If !Stored {
Stored := True
BackUpClip := ClipboardAll ; ClipboardAll must be on its own line
} Else
SetTimer, %A_ThisFunc%, Off
LongCopy := A_TickCount, Clipboard := "", LongCopy -= A_TickCount ; LongCopy gauges the amount of time it takes to empty the clipboard which can predict how long the subsequent clipwait will need
If (Text = "") {
SendInput, ^c
ClipWait, LongCopy ? 0.6 : 0.2, True
} Else {
Clipboard := LastClip := Text
ClipWait, 10
SendInput, ^v
}
SetTimer, %A_ThisFunc%, -700
Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter}
If (Text = "")
Return LastClip := Clipboard
Else If (ReSelect = True) or (Reselect and (StrLen(Text) < 3000)) {
StringReplace, Text, Text, `r, , All
SendInput, % "{Shift Down}{Left " StrLen(Text) "}{Shift Up}"
}
}
Return
Clip:
Return Clip()
}