ControlSend发送额外的换行符

时间:2018-08-13 06:59:08

标签: autohotkey

我正在尝试使用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
> ----

3 个答案:

答案 0 :(得分:1)

尝试

append(){
SetKeyDelay, 10, 10
Clipboard := RTrim(Clipboard, "`r`n") ; remove the last CRLF
ControlSend,Edit1,% Clipboard,ahk_exe notepad.exe
}

https://autohotkey.com/docs/commands/Trim.htm

答案 1 :(得分:1)

也尝试:

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

答案 2 :(得分:1)

另一种方法:

foreach($odkazy as $odkaz) {

   // ... rest of your code here    
   $items[] = $item;
   $html->clear();
   unset($item); // ADD THIS HERE 
   unset($html);

}

print_r($items);

https://autohotkey.com/docs/commands/LoopParse.htm