我正在编写一个需要显示数组变量值的 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和 TrayTip .
MsgBox, % MyArray[1]
Traytip, , % "The first value is " MyArray[1]
也可以看看:
关于arrays - 如何在 Autohotkey 中发送数组变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45637374/