Skip to content

Instantly share code, notes, and snippets.

@shokinn
Last active June 10, 2021 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shokinn/b26c5c3dd10dd685808c958e954f3c14 to your computer and use it in GitHub Desktop.
Save shokinn/b26c5c3dd10dd685808c958e954f3c14 to your computer and use it in GitHub Desktop.
AutoHotKey clipboard typer (send your clipboard as painfully slow keystrokes)
SleepBeforeType = 2000 ; sleep in ms
KeystrokeDelay = 200 ; delay between keystrokes in ms
; 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()
}
^F12::
Clipboard := Clip()
Sleep %SleepBeforeType%
SetKeyDelay, %KeystrokeDelay%
Send, %Clipboard%
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment