Paste through remote desktop connections

I have to tunnel through three remote desktop connections in order to run SSMS on a computer that is allowed to connect to a production SQL server. Somewhere in the tunnel I lose the ability to paste text from my local machine into the remote machine. Generally I’m just hunting for specific data, so it isn’t a big deal to compose new SQL for that purpose.

At other times, however, it’s a real pain having to retype a long query that I’ve already composed and run on a test instance. In those situations, I hit WIN + b, thanks to AutoHotKey:

#b:: ; Simulate typing of the text on the clipboard
KeyWait, LWin ; Ensure that the Windows key has been lifted.
KeyWait, RWin
ToPaste = %ClipBoard% ; Convert to text
Sleep 100
StringReplace, ToPaste, ToPaste, `r`n, `n, All ; Prevent CR+LF from causing two newlines
Sleep 100
SendRaw %ToPaste% ; SendRaw simulates typing the characters exactly, including AHK's special !^#+ characters

You get to watch the computer do the typing, so be patient. If you press any keys or click around, this script will just keep on typing and mix in your live actions with what it’s typing.

You do have to watch out for the helpful features of whatever program you’re “pasting” into. Auto-indent exaggerates already-indented text that you “paste” and sometimes auto-complete suggestions are accepted in place of what you wanted.

Regardless, this little script saves time and frustration.

Paste through remote desktop connections

Clean Paste

While there are times that I appreciate the way copy-paste retains formatting in Windows, it very frequently causes headaches. Some of the applications in the Office suite provide the ability to paste without formatting, but there are still many times that unwanted formatting tags along or causes problems.

AutoHotKey to the rescue!

The following little script lets me hit the Windows key and “v” and get a clean paste without formatting:

; Copied from
#v:: ; Text–only paste from ClipBoard | WIN and V keys are the hotkey
KeyWait, LWin ; Wait for the Windows key to be lifted,
KeyWait, RWin ; since it would sometimes combine with the pasted text.
OldClip = %ClipBoardAll% ; Save formatted text for later
ClipBoard = %ClipBoard% ; Convert to text
Send ^v ; For best compatibility: SendPlay | simulates pressing CRTL and V keys
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %OldClip% ; Restore original ClipBoard
VarSetCapacity(OldClip, 0) ; Free memory

view raw
hosted with ❤ by GitHub

This is pretty much just copied from a forum post. Nice and fast and no bad formatting.

Clean Paste