ControlSend 发送额外的换行符
ControlSend sends extra newline
我正在尝试使用 ControlSend 向记事本发送文本。但它会将带有额外换行符的文本发送到记事本。
append()
{
SetKeyDelay, 10, 10
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
#If GetKeyState("Ctrl") && GetKeyState("Shift") ;Seçilileri dosyay kaydeder.
{
a & s::
sleep 30
Send, ^c
sleep 30
Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
sleep 30
append()
sleep 30
Return
}
它发送这个:
> [source,java]
> ----
> SetKeydelay, 10, 10
>
> SetKeyDelay, 0, 10
>
> SetKeyDelay, 0, 10
> ----
而不是这个:
> [source,java]
> ----
> SetKeydelay, 10, 10
> SetKeyDelay, 0, 10
> SetKeyDelay, 0, 10
> ----
尝试
append(){
SetKeyDelay, 10, 10
Clipboard := RTrim(Clipboard, "`r`n") ; remove the last CRLF
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
也试试:
append(){
SetKeyDelay, 10, 10
; Remove all blank lines from the text in a variable:
Loop
{
Clipboard := StrReplace(Clipboard, "`r`n`r`n", "`r`n", Count)
if Count = 0 ; No more replacements needed.
break
}
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
https://autohotkey.com/docs/commands/StringReplace.htm#Examples
另一种方法:
append(){
SetKeyDelay, 10, 10
Loop, parse, Clipboard, `n
ControlSend,Edit1,%A_LoopField%,ahk_exe notepad.exe
}
我正在尝试使用 ControlSend 向记事本发送文本。但它会将带有额外换行符的文本发送到记事本。
append()
{
SetKeyDelay, 10, 10
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
#If GetKeyState("Ctrl") && GetKeyState("Shift") ;Seçilileri dosyay kaydeder.
{
a & s::
sleep 30
Send, ^c
sleep 30
Clipboard := "`n[source]`n----`n" . Clipboard . "`n---- `n`n"
sleep 30
append()
sleep 30
Return
}
它发送这个:
> [source,java]
> ----
> SetKeydelay, 10, 10
>
> SetKeyDelay, 0, 10
>
> SetKeyDelay, 0, 10
> ----
而不是这个:
> [source,java]
> ----
> SetKeydelay, 10, 10
> SetKeyDelay, 0, 10
> SetKeyDelay, 0, 10
> ----
尝试
append(){
SetKeyDelay, 10, 10
Clipboard := RTrim(Clipboard, "`r`n") ; remove the last CRLF
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
也试试:
append(){
SetKeyDelay, 10, 10
; Remove all blank lines from the text in a variable:
Loop
{
Clipboard := StrReplace(Clipboard, "`r`n`r`n", "`r`n", Count)
if Count = 0 ; No more replacements needed.
break
}
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}
https://autohotkey.com/docs/commands/StringReplace.htm#Examples
另一种方法:
append(){
SetKeyDelay, 10, 10
Loop, parse, Clipboard, `n
ControlSend,Edit1,%A_LoopField%,ahk_exe notepad.exe
}