arrays - 如何在 Autohotkey 中发送数组变量的值?

标签 arrays autohotkey

我正在编写一个需要显示数组变量值的 AutoHotkey 脚本,但它似乎无法正常工作。

MyArray := ["one", "two", "three"]

send MyArray[1]     ; "MyArray[1]"
send MyArray%1%     ; "MyArray"
send %MyArray1%     ; <empty>
send % MyArray%1%   ; <empty>
;send %MyArray%1%   ; 'Error: Variable name missing its ending percent sign'
;send %MyArray%1%%  ; 'Error: Empty variable reference (%%)'
;send %MyArray[1]%  ; 'Error: Variable name contains an illegal character'

我找到了 posts on the AHK forums 声称我可以使用 send %MyArray1%send % MyArray %1% ,但两个命令都只引用空变量。

如何在 AutoHotkey 脚本中发送数组的值?

最佳答案

使用单个 %强制单个参数的表达模式。

MyArray := ["one", "two", "three"]  ; initialize array
Send, % MyArray[1]                  ; send "one"

这可以与使用引号 "" 的常规文本结合起来。
Send, % "The first value in my array is " MyArray[1]

表达式模式可用于任何命令,包括 MsgBoxTrayTip .
MsgBox, % MyArray[1]
Traytip, , % "The first value is " MyArray[1]

也可以看看:
  • AutoHotkey - Variables and Expressions
  • When are single percent % signs used in the script?
  • 关于arrays - 如何在 Autohotkey 中发送数组变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45637374/

    相关文章:

    regex - Autohotkey 使用正则表达式提取文本

    arrays - 多个 Json 文件或具有多个数组的单个文件

    c - 在 C 中的 "__' 行和 '___' 列之后停止数组?

    c++ - 指针可以在函数调用期间转换为数组吗?

    python - 快速检查数组中的元素是否在另一个数组中(2D)

    windows - 使用 AutoHotKey (AHK) 创建类似 Vim 的功能

    autohotkey - 使用鼠标滚轮在多个显示器的任务栏上更改音量

    autohotkey - 如何让 Autohotkey 'listen' 更改文件?

    arrays - 使用类型推断展平嵌套数组

    autohotkey - 如何在 Autohotkey 中重新映射 CTRL-x CTRL-c?