代码之家  ›  专栏  ›  技术社区  ›  Jason Berger

“发送%variable%”在发送变量之前评估变量

  •  0
  • Jason Berger  · 技术社区  · 7 年前

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

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

    InputBox variable, Variable
    Send %variable%
    

    然后,如果我输入:

    helloworld{输入}

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

    我如何强制它写入%variable%,而不事先解释它?

    2 回复  |  直到 7 年前
        1
  •  3
  •   S. User18    7 年前

    我同意另一个答案,即使用FileAppend将是一种更好的方法。但是,如果确实希望使用send命令完成此操作,则需要使用 {raw} 模式您可以阅读 {原始} 在文件中: https://autohotkey.com/docs/commands/Send.htm

    InputBox variable, Variable
    Send, {raw}%variable%
    
        2
  •  2
  •   Relax    7 年前

    从scriptA编写另一个脚本(scriptB)的最简单方法是使用 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