在自动热键上循环对象

时间:2017-12-08 23:30:06

标签: loops autohotkey

如何循环显示这些颜色,以便在第一次按ctr j时显示"红色"第二次"蓝"等等 这就是我到目前为止所拥有的

^j::
colors := Object("red","blue","green", "black")
for key, in colors
    s .= key 
Send, % s
Return

但是,当我运行它时,我得到的输出是

greenredgreenredgreenredgreenredgreenred

1 个答案:

答案 0 :(得分:1)

; Creating an array: 
colors := ["red","blue","green","black"]
; or: 
; colors := Array("red","blue","green", "black")

;  MaxIndex returns the number of items: 
MaxIndex := colors.MaxIndex()

^j::
    Index++ ; increases the number in the variable "Index" by 1, each time you press ^j.
    Send, % colors[Index]
    If (Index = MaxIndex)
        Index = 0 ; reset
return

https://autohotkey.com/docs/Objects.htm#Usage_Simple_Arrays