【问题标题】:How to spread a variable in AutoHotkey?如何在 AutoHotkey 中传播变量?
【发布时间】:2021-11-06 23:00:12
【问题描述】:

在 JavaScript 中,我们使用 spread operator 来传播项目数组,例如

const arr = [1, 2, 3]

console.log(...arr) // 1 2 3

我想在 AHK 中实现类似的效果:

Position := [A_ScreenWidth / 2, A_ScreenHeight]

MouseMove Position ; ???? how to spread it?

【问题讨论】:

  • 据我所知,AHK 中没有扩展语法。您必须“手动”访问数组元素。

标签: javascript arrays variables autohotkey spread-syntax


【解决方案1】:

AFAIK,AHK 中没有扩展语法,但有一些替代方案:

对于大数组,您可以使用:

position := [A_ScreenWidth / 2, A_ScreenHeight]
Loop,% position.Count()
    MsgBox % position[A_Index] ; show a message box with the content of any value

position := [A_ScreenWidth / 2, A_ScreenHeight]
For index, value in position
    MsgBox % value ; show a message box with the content of any value

在您的示例中,可以是:

position := [A_ScreenWidth / 2, A_ScreenHeight]
MouseMove, position[1], position[2]

这会将您的鼠标移动到屏幕的底部中间。

为了避免小数,您可以使用Floor()Round()Ceil() 函数,例如:

position := [ Floor( A_ScreenWidth / 2 ), Round( A_ScreenHeight ) ]
Loop,% position.Count()
    MsgBox % position[A_Index] ; show a message box with the content of any value

【讨论】:

    猜你喜欢
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-19
    相关资源
    最近更新 更多