1

I need to be able to "type" the content of my local clipboard in a remote session (remote PC is properly locked, no clipboard sharing, the only accepted input is key presses)

With AHK, I found the following one-liner to do what I need:

^+1::Send %Clipboard%

It works fine, except that it doubles every EOL i.e. if my clipboard contains:

line1
line2
line3

then executing the script results in "typing":

line1

line2

line3

Any ideas how to fix this?

Piotr L
  • 1,065
  • 1
  • 12
  • 29

2 Answers2

2

Your remote session / remote PC is probably windows right? When typing "\r" and "\n" are interpreted in the same way. You need to get rid of the extra linebreak which can be done like this:

^+1::Send % RegExReplace(clipboard, "\r\n?|\n\r?", "`n")

I didnt test the code, there might be a issue sending it direcly to "Send", maybe you want to put the return value of RegExReplace into a variable and output it that way.

mhaendler
  • 124
  • 5
  • That works, thank you. I am only starting my adventure with AHK, and I am not familiar with its capabilities really. – Piotr L Aug 08 '23 at 10:21
  • I discovered that this approach tends to skip shift key presses, resulting in, for example, underscores being sent as hyphens, or brackets as numbers and so on. – Piotr L Aug 18 '23 at 10:19
1

While @mhaendler's answer is correct (it solves the core issue: doubling EOL characters), in RDP scenario it tends to skip shift key presses, resulting in incorrect characters being sent across.

I found that the below script works perfectly for me - 100% of characters are correct at target, every time:

SendMode Event
SetKeyDelay, 5
^+1::
{
    Sleep 500
    transformedText := RegExReplace(clipboard, "\r\n?|\n\r?", "`n")
    Send, {Text}%transformedText%
}

(the Sleep 500 command is there because my shortcut to activate the script contains shift and control keys, and they affect the output - half a second is enough time to release both shift and control before the keystrokes kick in).

Piotr L
  • 1,065
  • 1
  • 12
  • 29