【发布时间】:2021-08-18 13:13:39
【问题描述】:
我需要做一件非常简单的事情:创建一个快捷方式,在里面粘贴带有新行的文本,像这样
first line
second line
我知道我可以使用 send、sendinput 或 sendinput {text} 来做到这一点
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^!q::
Send first line `nsecond line`n
return
^!w::
SendInput first line `nsecond line`n
return
^!e::
SendInput {text}first line `nsecond line`n
return
我看到它可能有风险,因为在所有这些方面,新行都可以充当 Enter 命令,我想避免这种行为。
所以我尝试使用剪贴板:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
#SingleInstance force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
^!r::
string = first line `nsecond line`n
prevClipboard := ClipboardAll
Clipboard := string
ClipWait, 1, 1 ; Wait for the clipboard to contain the copied text.
Send ^v
Clipboard := prevClipboard ; keep previous cliboard content
return
在我的个人计算机上它可以工作,但在另一种情况下它不起作用,我在一个非常慢的虚拟机中使用便携式 AHK,第一次它工作,第二次只粘贴实际剪贴板内容
有没有办法做到这一点?
我进行了测试以验证我的快捷方式是否按下了回车键: 在文件资源管理器中选择一个文件,按 Shift + Canc,这将显示一个弹出窗口“您确定要永久删除吗?” 然后按下我的 ahk 快捷方式,它就像一个 Enter 键并删除了文件
【问题讨论】:
-
我认为这在一般情况下是不可能的? (其他程序可能任意滞后)
-
是的,这似乎是不可能的。请参阅load - AutoHotKey Copy file to clipboard and paste - Stack Overflow——那里唯一的答案建议等待 2 秒。
-
还有
ControlSetText
标签: autohotkey