如何使用 AutoHotKey 发送文本,结果文本输出如下?
Alfa
Bravo
Charlie
Delta
我尝试过使用这个操作:
text =
(
Alfa
Bravo
Charlie
Delta
)
Send % text
Return
但是会返回以下文本:
Alfa
Bravo
Charlie
Delta
所以看起来压痕空间积累了,因此压痕变得错误。
在这种情况下最快的解决方案是使用剪贴板:
ClipSaved := ClipboardAll ; save the entire clipboard to the variable ClipSaved
clipboard := "" ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
clipboard = ; copy this text:
(
Alfa
Bravo
Charlie
Delta
)
ClipWait, 1 ; wait for the clipboard to contain data.
If (!ErrorLevel) ; If NOT ErrorLevel ClipWait found data on the clipboard
Send, ^v ; paste the text
Sleep, 300 ; don't change the clipboard while pasting! (Sleep > 0)
clipboard := ClipSaved ; restore original clipboard
VarSetCapacity(ClipSaved, 0) ; free the memory
return
如果您经常需要发送如此复杂或长的文本,您可以创建一个函数,以免每次都重复整个代码:
my_text =
(
Alfa
Bravo
Charlie
Delta
)
Send(my_text)
return
Send(text){
ClipSaved := ClipboardAll
clipboard := ""
clipboard := text
ClipWait, 1
If (!ErrorLevel)
Send, ^v
Sleep, 300
clipboard := ClipSaved
VarSetCapacity(ClipSaved, 0)
}
另请参阅JoinString。