From 5e67fe93594f82a93013deecaeabd0fabbe3c977 Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Mon, 19 Apr 2021 12:44:16 +0200 Subject: [PATCH 1/9] Update Clip.ahk forked own version: Function no longer overwrites clipboard by default if used to retrieve marked selection via fn-call "out:=fClip()" ;; (this is equivalent to fClip(,,1) OG function by berban tended to lock down shift/winkey/ctrl/alt (make them sticky), so I am explicitly unsticking them. --- Clip.ahk | 88 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 12 deletions(-) diff --git a/Clip.ahk b/Clip.ahk index 34b3fed..09b66ba 100644 --- a/Clip.ahk +++ b/Clip.ahk @@ -1,36 +1,100 @@ ; Clip() - Send and Retrieve Text Using the Clipboard ; by berban - updated February 18, 2019 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 -Clip(Text="", Reselect="") + +; adapted by Gewerd Strauss + +fClip(Text="", Reselect="",Restore:=1) { + ClipStore:=Clipboard + if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos. + { + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor=true + } Static BackUpClip, Stored, LastClip - If (A_ThisLabel = A_ThisFunc) { + If (A_ThisLabel = A_ThisFunc) + { If (Clipboard == LastClip) Clipboard := BackUpClip BackUpClip := LastClip := Stored := "" - } Else { - If !Stored { + } + Else + { + If !Stored + { Stored := True BackUpClip := ClipboardAll ; ClipboardAll must be on its own line - } Else + } + 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 + If (Text = "") ; No text is pasted, hence we pull it. + { + SendInput, ^c ClipWait, LongCopy ? 0.6 : 0.2, True - } Else { + } + Else + { Clipboard := LastClip := Text ClipWait, 10 SendInput, ^v + if MoveCursor + { + if WinActive("E-Mail - - Google Chrome") ; removed identifiying information. + { + WinActivate + sleep, 20 + WinActivate, "E-Mail - - Google Chrome" + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + + } + else + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + } } SetTimer, %A_ThisFunc%, -700 Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} - If (Text = "") - Return LastClip := Clipboard + If (Text = "") ; we are pulling text rn, not pasting + { + SetTimer, %A_ThisFunc%, Off + { + f_unstickKeys() + if !Restore + return LastClip := Clipboard + else + LastClip := Clipboard + Clipboard:="" + ClipWait, LongCopy ? 0.6 : 0.2, True + Clipboard:=ClipStore + Return LastClip + } + } Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) + { + SetTimer, %A_ThisFunc%, Off SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + } } + f_unstickKeys() Return - Clip: - Return Clip() + fClip: + f_unstickKeys() + Return fClip() +} + +f_unstickKeys() +{ + SendInput, {Ctrl Up} + SendInput, {V Up} + SendInput, {Shift Up} + SendInput, {Alt Up} } From 1f0f990887064a6d6af0953311cad550c71d23e0 Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Wed, 5 May 2021 20:55:39 +0200 Subject: [PATCH 2/9] updated fClip --- .../Clip.ahk/20210505205455/Clip.ahk | 100 ++++++++++++++++++ Clip.ahk | 75 +++++++++++-- 2 files changed, 165 insertions(+), 10 deletions(-) create mode 100644 AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk diff --git a/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk b/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk new file mode 100644 index 0000000..09b66ba --- /dev/null +++ b/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk @@ -0,0 +1,100 @@ +; Clip() - Send and Retrieve Text Using the Clipboard +; by berban - updated February 18, 2019 +; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 + +; adapted by Gewerd Strauss + +fClip(Text="", Reselect="",Restore:=1) +{ + ClipStore:=Clipboard + if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos. + { + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor=true + } + 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 = "") ; No text is pasted, hence we pull it. + { + SendInput, ^c + ClipWait, LongCopy ? 0.6 : 0.2, True + } + Else + { + Clipboard := LastClip := Text + ClipWait, 10 + SendInput, ^v + if MoveCursor + { + if WinActive("E-Mail - - Google Chrome") ; removed identifiying information. + { + WinActivate + sleep, 20 + WinActivate, "E-Mail - - Google Chrome" + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + + } + else + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + } + } + SetTimer, %A_ThisFunc%, -700 + Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} + If (Text = "") ; we are pulling text rn, not pasting + { + SetTimer, %A_ThisFunc%, Off + { + f_unstickKeys() + if !Restore + return LastClip := Clipboard + else + LastClip := Clipboard + Clipboard:="" + ClipWait, LongCopy ? 0.6 : 0.2, True + Clipboard:=ClipStore + Return LastClip + } + } + Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) + { + SetTimer, %A_ThisFunc%, Off + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + } + } + f_unstickKeys() + Return + fClip: + f_unstickKeys() + Return fClip() +} + +f_unstickKeys() +{ + SendInput, {Ctrl Up} + SendInput, {V Up} + SendInput, {Shift Up} + SendInput, {Alt Up} +} diff --git a/Clip.ahk b/Clip.ahk index 09b66ba..de3f6e3 100644 --- a/Clip.ahk +++ b/Clip.ahk @@ -1,18 +1,24 @@ -; Clip() - Send and Retrieve Text Using the Clipboard -; by berban - updated February 18, 2019 -; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 + ;Clip() - Send and Retrieve Text Using the Clipboard + ;by berban - updated February 18, 2019 + ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 -; adapted by Gewerd Strauss + ;adapted by Gewerd Strauss fClip(Text="", Reselect="",Restore:=1) { + BlockInput,On ClipStore:=Clipboard if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos. { move := StrLen(Text) - RegExMatch(Text, "[&|]") Text := RegExReplace(Text, "[&|]") sleep, 20 - MoveCursor=true + MoveCursor:=true + } + Else + { + MoveCursor:=false + move:=1 ; offset the left-moves for the edgecase that this is not guarded by movecursor } Static BackUpClip, Stored, LastClip If (A_ThisLabel = A_ThisFunc) @@ -43,16 +49,16 @@ fClip(Text="", Reselect="",Restore:=1) SendInput, ^v if MoveCursor { - if WinActive("E-Mail - - Google Chrome") ; removed identifiying information. + if WinActive("E-Mail – Claudius-Simon.Appel@hsrw.org") { WinActivate sleep, 20 - WinActivate, "E-Mail - - Google Chrome" + BlockInput,On + WinActivate, "E-Mail – Claudius-Simon.Appel@hsrw.org" if !ReSelect and (ReSelect = False) SendInput, % "{Left " move-1 "}" else if (Reselect="") SendInput, % "{Left " move-1 "}" - } else if !ReSelect and (ReSelect = False) @@ -63,18 +69,21 @@ fClip(Text="", Reselect="",Restore:=1) } SetTimer, %A_ThisFunc%, -700 Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} - If (Text = "") ; we are pulling text rn, not pasting + If (Text = "") ; we are pulling, not pasting { SetTimer, %A_ThisFunc%, Off { f_unstickKeys() if !Restore + { + BlockInput, Off return LastClip := Clipboard - else + } LastClip := Clipboard Clipboard:="" ClipWait, LongCopy ? 0.6 : 0.2, True Clipboard:=ClipStore + BlockInput,Off Return LastClip } } @@ -85,16 +94,62 @@ fClip(Text="", Reselect="",Restore:=1) } } f_unstickKeys() + BlockInput, Off Return fClip: f_unstickKeys() + BlockInput,Off Return fClip() } + f_unstickKeys() { + BlockInput,On SendInput, {Ctrl Up} SendInput, {V Up} SendInput, {Shift Up} SendInput, {Alt Up} + BlockInput,Off +} + + +/* original by berban https://github.com/berban/Clip/blob/master/Clip.ahk + ; Clip() - Send and Retrieve Text Using the Clipboard +; by berban - updated February 18, 2019 +; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 +Clip(Text="", Reselect="") +{ + 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + } + Return + Clip: + Return Clip() } +*/ + From 37630c3fb8048e3cbdf05bbfe20e01147d15337f Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Mon, 24 May 2021 14:03:19 +0200 Subject: [PATCH 3/9] adapted berban's original code, reverted back to using berban's version after spotting some annoying timing bugs that I couldn't care enough to hunt down. Changed his code instead. left own, slightly more error-prone version as a backup by changing the parameter "DefaultMethod" --- Clip.ahk | 263 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 157 insertions(+), 106 deletions(-) diff --git a/Clip.ahk b/Clip.ahk index de3f6e3..1b54cf9 100644 --- a/Clip.ahk +++ b/Clip.ahk @@ -1,101 +1,152 @@ - ;Clip() - Send and Retrieve Text Using the Clipboard + ;Clip() - Send and Retrieve Text Using the Clipboard ;by berban - updated February 18, 2019 ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 - ;adapted by Gewerd Strauss + ;modified by Gewerd Strauss -fClip(Text="", Reselect="",Restore:=1) +fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) { - BlockInput,On - ClipStore:=Clipboard - if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos. + ;m(DefaultMethod) + if !DefaultMethod { - move := StrLen(Text) - RegExMatch(Text, "[&|]") - Text := RegExReplace(Text, "[&|]") - sleep, 20 - MoveCursor:=true - } - Else - { - MoveCursor:=false - move:=1 ; offset the left-moves for the edgecase that this is not guarded by movecursor - } - Static BackUpClip, Stored, LastClip - If (A_ThisLabel = A_ThisFunc) - { - If (Clipboard == LastClip) - Clipboard := BackUpClip - BackUpClip := LastClip := Stored := "" - } - Else - { - If !Stored + BlockInput,On + if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets { - Stored := True - BackUpClip := ClipboardAll ; ClipboardAll must be on its own line - } + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor:=true + } 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 = "") ; No text is pasted, hence we pull it. { - SendInput, ^c - ClipWait, LongCopy ? 0.6 : 0.2, True + MoveCursor:=false + move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor + } + Static BackUpClip, Stored, LastClip + If (A_ThisLabel = A_ThisFunc) + { + If (Clipboard == LastClip) + Clipboard := BackUpClip + BackUpClip := LastClip := Stored := "" } Else { - Clipboard := LastClip := Text - ClipWait, 10 - SendInput, ^v - if MoveCursor + If !Stored { - if WinActive("E-Mail – Claudius-Simon.Appel@hsrw.org") + 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 = "") ; No text is pasted, hence we pull it. + { + SendInput, ^c + ClipWait, LongCopy ? 0.6 : 0.2, True + } + Else + { + Clipboard := LastClip := Text + ClipWait, 10 + SendInput, ^v + ;MsgBox, mc:%MoveCursor% + if MoveCursor { - WinActivate - sleep, 20 - BlockInput,On - WinActivate, "E-Mail – Claudius-Simon.Appel@hsrw.org" - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-1 "}" + if WinActive("E-Mail – ") and Winactive("— Mozilla Firefox") + { + WinActivate + sleep, 20 + BlockInput,On + WinActivate, "E-Mail – " + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + } + else + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-2 "}" else if (Reselect="") - SendInput, % "{Left " move-1 "}" - } - else - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-1 "}" - else if (Reselect="") - SendInput, % "{Left " move-1 "}" + { + SendInput, % "{Left " move-2 "}" + } + } } - } - SetTimer, %A_ThisFunc%, -700 - Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} - If (Text = "") ; we are pulling, not pasting - { - SetTimer, %A_ThisFunc%, Off + SetTimer, %A_ThisFunc%, -700 + Sleep 200 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} + If (Text = "") ; we are pulling, not pasting { - f_unstickKeys() - if !Restore + SetTimer, %A_ThisFunc%, Off { - BlockInput, Off - return LastClip := Clipboard + f_unstickKeys() + if !Restore + { + BlockInput, Off + return LastClip := Clipboard + } + LastClip := Clipboard + ClipWait, LongCopy ? 0.6 : 0.2, True + BlockInput,Off + Return LastClip } - LastClip := Clipboard - Clipboard:="" - ClipWait, LongCopy ? 0.6 : 0.2, True - Clipboard:=ClipStore - BlockInput,Off - Return LastClip + } + Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) + { + SetTimer, %A_ThisFunc%, Off + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" } } - Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) + f_unstickKeys() + BlockInput, Off + Return + + } + else + { + if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets + { + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor:=true + } + Else { - SetTimer, %A_ThisFunc%, Off - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + MoveCursor:=false + move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor + } + 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + if Move and !ReSelect{ + SendInput, % "{Left " move-2 "}" + } } + Return + } - f_unstickKeys() - BlockInput, Off - Return fClip: f_unstickKeys() BlockInput,Off @@ -105,12 +156,12 @@ fClip(Text="", Reselect="",Restore:=1) f_unstickKeys() { - BlockInput,On + BlockInput, On SendInput, {Ctrl Up} SendInput, {V Up} SendInput, {Shift Up} SendInput, {Alt Up} - BlockInput,Off + BlockInput, Off } @@ -118,38 +169,38 @@ f_unstickKeys() ; Clip() - Send and Retrieve Text Using the Clipboard ; by berban - updated February 18, 2019 ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 -Clip(Text="", Reselect="") -{ - 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 + Clip(Text="", Reselect="") + { + Static BackUpClip, Stored, LastClip + If (A_ThisLabel = A_ThisFunc) { + If (Clipboard == LastClip) + Clipboard := BackUpClip + BackUpClip := LastClip := Stored := "" } Else { - Clipboard := LastClip := Text - ClipWait, 10 - SendInput, ^v + 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" } - 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + Return + Clip: + Return Clip() } - Return - Clip: - Return Clip() -} */ From ce6b9a3fb81b3f0612d52a7a9021e0c908843467 Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Sat, 17 Jul 2021 20:35:24 +0200 Subject: [PATCH 4/9] Delete AHK-Studio Backup/Clip.ahk/20210505205455 directory --- .../Clip.ahk/20210505205455/Clip.ahk | 100 ------------------ 1 file changed, 100 deletions(-) delete mode 100644 AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk diff --git a/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk b/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk deleted file mode 100644 index 09b66ba..0000000 --- a/AHK-Studio Backup/Clip.ahk/20210505205455/Clip.ahk +++ /dev/null @@ -1,100 +0,0 @@ -; Clip() - Send and Retrieve Text Using the Clipboard -; by berban - updated February 18, 2019 -; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 - -; adapted by Gewerd Strauss - -fClip(Text="", Reselect="",Restore:=1) -{ - ClipStore:=Clipboard - if RegExMatch(Text,"[&|]") ; check if needle contains cursor-pos. - { - move := StrLen(Text) - RegExMatch(Text, "[&|]") - Text := RegExReplace(Text, "[&|]") - sleep, 20 - MoveCursor=true - } - 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 = "") ; No text is pasted, hence we pull it. - { - SendInput, ^c - ClipWait, LongCopy ? 0.6 : 0.2, True - } - Else - { - Clipboard := LastClip := Text - ClipWait, 10 - SendInput, ^v - if MoveCursor - { - if WinActive("E-Mail - - Google Chrome") ; removed identifiying information. - { - WinActivate - sleep, 20 - WinActivate, "E-Mail - - Google Chrome" - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-1 "}" - else if (Reselect="") - SendInput, % "{Left " move-1 "}" - - } - else - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-1 "}" - else if (Reselect="") - SendInput, % "{Left " move-1 "}" - } - } - SetTimer, %A_ThisFunc%, -700 - Sleep 20 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} - If (Text = "") ; we are pulling text rn, not pasting - { - SetTimer, %A_ThisFunc%, Off - { - f_unstickKeys() - if !Restore - return LastClip := Clipboard - else - LastClip := Clipboard - Clipboard:="" - ClipWait, LongCopy ? 0.6 : 0.2, True - Clipboard:=ClipStore - Return LastClip - } - } - Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) - { - SetTimer, %A_ThisFunc%, Off - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" - } - } - f_unstickKeys() - Return - fClip: - f_unstickKeys() - Return fClip() -} - -f_unstickKeys() -{ - SendInput, {Ctrl Up} - SendInput, {V Up} - SendInput, {Shift Up} - SendInput, {Alt Up} -} From 2325f4298a8fce607f782f6882ecf54380b208cf Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Sat, 17 Jul 2021 20:36:30 +0200 Subject: [PATCH 5/9] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c90fdf1..04b9846 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ Clip() - Send and Retrieve Text using the Clipboard Forum link: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 + +edited and changed by Gewerd-Strauss From b8470dc13df67fd6eed26a709ab71defe47c1715 Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Wed, 8 Dec 2021 15:43:50 +0100 Subject: [PATCH 6/9] minimal rename --- Clip.ahk => fClip.ahk | 2 -- 1 file changed, 2 deletions(-) rename Clip.ahk => fClip.ahk (99%) diff --git a/Clip.ahk b/fClip.ahk similarity index 99% rename from Clip.ahk rename to fClip.ahk index 1b54cf9..4612872 100644 --- a/Clip.ahk +++ b/fClip.ahk @@ -6,7 +6,6 @@ fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) { - ;m(DefaultMethod) if !DefaultMethod { BlockInput,On @@ -49,7 +48,6 @@ fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) Clipboard := LastClip := Text ClipWait, 10 SendInput, ^v - ;MsgBox, mc:%MoveCursor% if MoveCursor { if WinActive("E-Mail – ") and Winactive("— Mozilla Firefox") From e9f9aa97e38c5d57b1b2b987b8838c31cf94151b Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Wed, 8 Dec 2021 15:55:18 +0100 Subject: [PATCH 7/9] Create Clip.ahk --- Clip.ahk | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 Clip.ahk diff --git a/Clip.ahk b/Clip.ahk new file mode 100644 index 0000000..b9a55c4 --- /dev/null +++ b/Clip.ahk @@ -0,0 +1,208 @@ + ;Clip() - Send and Retrieve Text Using the Clipboard + ;by berban - updated February 18, 2019 + ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 + + ;modified by Gewerd Strauss + +fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) +{ + /* + Parameters + Text: variable whose contents to paste. + */ + if !DefaultMethod + { + BlockInput,On + if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets + { + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor:=true + } + Else + { + MoveCursor:=false + move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor + } + 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 = "") ; No text is pasted, hence we pull it. + { + SendInput, ^c + ClipWait, LongCopy ? 0.6 : 0.2, True + } + Else + { + Clipboard := LastClip := Text + ClipWait, 10 + SendInput, ^v + if MoveCursor + { + if WinActive("E-Mail – ") and Winactive("— Mozilla Firefox") + { + WinActivate + sleep, 20 + BlockInput,On + WinActivate, "E-Mail – " + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-1 "}" + else if (Reselect="") + SendInput, % "{Left " move-1 "}" + } + else + if !ReSelect and (ReSelect = False) + SendInput, % "{Left " move-2 "}" + else if (Reselect="") + { + SendInput, % "{Left " move-2 "}" + } + } + } + SetTimer, %A_ThisFunc%, -700 + Sleep 200 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} + If (Text = "") ; we are pulling, not pasting + { + SetTimer, %A_ThisFunc%, Off + { + f_unstickKeys() + if !Restore + { + BlockInput, Off + return LastClip := Clipboard + } + LastClip := Clipboard + ClipWait, LongCopy ? 0.6 : 0.2, True + BlockInput,Off + Return LastClip + } + } + Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) + { + SetTimer, %A_ThisFunc%, Off + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + } + } + f_unstickKeys() + BlockInput, Off + Return + + } + else + { + if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets + { + move := StrLen(Text) - RegExMatch(Text, "[&|]") + Text := RegExReplace(Text, "[&|]") + sleep, 20 + MoveCursor:=true + } + Else + { + MoveCursor:=false + move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor + } + 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + if Move and !ReSelect{ + SendInput, % "{Left " move-2 "}" + } + } + Return + + } + fClip: + f_unstickKeys() + BlockInput,Off + Return fClip() +} + + +f_unstickKeys() +{ + BlockInput, On + SendInput, {Ctrl Up} + SendInput, {V Up} + SendInput, {Shift Up} + SendInput, {Alt Up} + BlockInput, Off +} + + +/* original by berban https://github.com/berban/Clip/blob/master/Clip.ahk + ; Clip() - Send and Retrieve Text Using the Clipboard +; by berban - updated February 18, 2019 +; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 + Clip(Text="", Reselect="") + { + 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) + SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" + } + Return + Clip: + Return Clip() + } +*/ + From 839779f20bfe8119586dd9900dc18557328f8997 Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Wed, 8 Dec 2021 16:12:06 +0100 Subject: [PATCH 8/9] Small fixes --- Clip.ahk | 208 ------------------------------------------------------ fClip.ahk | 7 ++ 2 files changed, 7 insertions(+), 208 deletions(-) delete mode 100644 Clip.ahk diff --git a/Clip.ahk b/Clip.ahk deleted file mode 100644 index b9a55c4..0000000 --- a/Clip.ahk +++ /dev/null @@ -1,208 +0,0 @@ - ;Clip() - Send and Retrieve Text Using the Clipboard - ;by berban - updated February 18, 2019 - ;https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 - - ;modified by Gewerd Strauss - -fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) -{ - /* - Parameters - Text: variable whose contents to paste. - */ - if !DefaultMethod - { - BlockInput,On - if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets - { - move := StrLen(Text) - RegExMatch(Text, "[&|]") - Text := RegExReplace(Text, "[&|]") - sleep, 20 - MoveCursor:=true - } - Else - { - MoveCursor:=false - move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor - } - 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 = "") ; No text is pasted, hence we pull it. - { - SendInput, ^c - ClipWait, LongCopy ? 0.6 : 0.2, True - } - Else - { - Clipboard := LastClip := Text - ClipWait, 10 - SendInput, ^v - if MoveCursor - { - if WinActive("E-Mail – ") and Winactive("— Mozilla Firefox") - { - WinActivate - sleep, 20 - BlockInput,On - WinActivate, "E-Mail – " - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-1 "}" - else if (Reselect="") - SendInput, % "{Left " move-1 "}" - } - else - if !ReSelect and (ReSelect = False) - SendInput, % "{Left " move-2 "}" - else if (Reselect="") - { - SendInput, % "{Left " move-2 "}" - } - } - } - SetTimer, %A_ThisFunc%, -700 - Sleep 200 ; Short sleep in case Clip() is followed by more keystrokes such as {Enter} - If (Text = "") ; we are pulling, not pasting - { - SetTimer, %A_ThisFunc%, Off - { - f_unstickKeys() - if !Restore - { - BlockInput, Off - return LastClip := Clipboard - } - LastClip := Clipboard - ClipWait, LongCopy ? 0.6 : 0.2, True - BlockInput,Off - Return LastClip - } - } - Else If ReSelect and ((ReSelect = True) or (StrLen(Text) < 3000)) - { - SetTimer, %A_ThisFunc%, Off - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" - } - } - f_unstickKeys() - BlockInput, Off - Return - - } - else - { - if InStr(Text,"&|") ;; check if needle contains cursor-pos. The needle must be &|, without brackets - { - move := StrLen(Text) - RegExMatch(Text, "[&|]") - Text := RegExReplace(Text, "[&|]") - sleep, 20 - MoveCursor:=true - } - Else - { - MoveCursor:=false - move:=1 ;; offset the left-moves for the edgecase that this is not guarded by movecursor - } - 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" - if Move and !ReSelect{ - SendInput, % "{Left " move-2 "}" - } - } - Return - - } - fClip: - f_unstickKeys() - BlockInput,Off - Return fClip() -} - - -f_unstickKeys() -{ - BlockInput, On - SendInput, {Ctrl Up} - SendInput, {V Up} - SendInput, {Shift Up} - SendInput, {Alt Up} - BlockInput, Off -} - - -/* original by berban https://github.com/berban/Clip/blob/master/Clip.ahk - ; Clip() - Send and Retrieve Text Using the Clipboard -; by berban - updated February 18, 2019 -; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 - Clip(Text="", Reselect="") - { - 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 and ((ReSelect = True) or (StrLen(Text) < 3000)) - SendInput, % "{Shift Down}{Left " StrLen(StrReplace(Text, "`r")) "}{Shift Up}" - } - Return - Clip: - Return Clip() - } -*/ - diff --git a/fClip.ahk b/fClip.ahk index 4612872..6e40316 100644 --- a/fClip.ahk +++ b/fClip.ahk @@ -6,6 +6,13 @@ fClip(Text="", Reselect="",Restore:=1,DefaultMethod:=1) { + /* + Parameters + Text: variable whose contents to paste. + Reselect: set true if you want to reselect pasted text for further processing + Restore: restore clipboard after using it. + DefaultMethod: keep true to use the original method. Recommended for anyone but Gewerd S./me, as I needed some extremely minute modifications in some places and expanded the whole function to be more readable for me. + */ if !DefaultMethod { BlockInput,On From ed3a99b5c76475350ece5ee1a5a94c81e622310b Mon Sep 17 00:00:00 2001 From: Gewerd-Strauss <80548781+Gewerd-Strauss@users.noreply.github.com> Date: Wed, 8 Dec 2021 16:16:36 +0100 Subject: [PATCH 9/9] Update README.md --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 04b9846..367a96f 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,22 @@ Clip() - Send and Retrieve Text using the Clipboard Forum link: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=62156 edited and changed by Gewerd-Strauss + +## Paste a variable while reliably restoring the clipboard + +``` +Numpad0:: +txt:="Hello World" +fClip(txt) +return +``` + +## Retrieving selected text + +``` +Numpad0:: +txt:=fClip() +msgbox, % txt +return +``` +For further explanation on the different parameters meaning, check the function itself.