AutoHotKey远程会话剪贴板模拟输入换行重复问题求助
Problem Cause
When using Send %Clipboard% to simulate keystrokes in a remote session, Windows-style line breaks (CRLF, represented as `r`n in AutoHotKey) are often interpreted as two separate newline triggers. Both the carriage return (`r) and line feed (`n) characters get translated into Enter presses, resulting in double newlines between lines.
Solutions
Solution 1: Use SendRaw for Literal Text Sending
SendRaw sends the clipboard content exactly as it is, without parsing special characters into commands. This avoids the double newline issue by preserving the original line break structure:
^+1::SendRaw %Clipboard%
Solution 2: Explicitly Replace Line Breaks with Single Enter Commands
If SendRaw doesn't work with your remote session (some environments may still misinterpret raw line breaks), you can replace all line break variants with a single {Enter} command. This ensures only one newline is sent per line break:
^+1:: ; Replace all line break types with a single Enter command processedText := StrReplace(Clipboard, "`r`n", "{Enter}") processedText := StrReplace(processedText, "`n", "{Enter}") processedText := StrReplace(processedText, "`r", "{Enter}") Send % processedText return
Solution 3: Simplified Single-Line Replacement
For a concise version targeting Windows-style CRLF line breaks directly:
^+1::Send % StrReplace(Clipboard, "`r`n", "{Enter}")
Notes
- Test which solution works best for your specific remote session environment, as some platforms handle line breaks differently.
- If working with Unix-style LF-only line breaks, adjust the replacement to target
`ninstead of`r`n.
内容的提问来源于stack exchange,提问作者Piotr L

