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

How do I send the value of an array variable in 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]

表达式模式可以与任何命令一起使用,包括MsgBox and TrayTip

MsgBox, % MyArray[1]
Traytip, , % "The first value is " MyArray[1]

另请参阅