Search code examples
autohotkeyclipboardend-of-line

AutoHotKey - clipboard - multiline - double EOL


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?


Solution

  • 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.