"Send %variable%" 在发送之前评估我的变量

"Send %variable%" evals my variable before sending it

我有一个自动热键脚本 (A) 可以编写另一个脚本 (B)。

我脚本中重要的一行(A):

InputBox variable, Variable
Send %variable%

然后,如果我输入:

helloworld{enter}

它将写入 "helloworld" 并在我的脚本中插入一个新行 (B) 而不是只写入“{enter}”

如何在不事先解释的情况下强制它写入 %variable% ?

从脚本编写另一个脚本(脚本)的最简单方法是使用 FileAppend:

variable = helloworld

FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk

Run, edit "C:\scriptB.ahk"
; or:
; Run, C:\scriptB.ahk

InputBox variable, Variable, Enter a variable:
if not ErrorLevel
{
FileAppend,
(
; a line of code
Send %variable%{enter}
; another line of code
)
,C:\scriptB.ahk
Run, edit "C:\scriptB.ahk"
; or:
; Run C:\scriptB.ahk
}
return

我同意另一个答案,即使用 FileAppend 是更好的方法。但是,如果您真的想使用发送命令来完成此操作,则需要使用 {raw} 模式。您可以在文档中阅读有关 {raw} 的信息: https://autohotkey.com/docs/commands/Send.htm

InputBox variable, Variable
Send, {raw}%variable%