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

One thought on “Paste through remote desktop connections

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s