按下某个键时切换循环?

时间:2015-02-24 02:00:09

标签: loops toggle autohotkey

例如,按TAB将关闭/打开此循环:

Loop
{ ;loop start
    GetKeyState, var, LButton, P
    If var = U
        Break
    Send {1}
    Random, r, 100, 400
    sleep r
}
return

这可能吗?

2 个答案:

答案 0 :(得分:0)

settimer

的示例
Settimer, MyLabel, 10

Tab::
Settimer, MyLabel, % (t:=!t)?"On":"Off"
Return

MyLabel::
    GetKeyState, var, LButton, P
    If var = U
        Settimer,, Off
    Send {1}
    Random, r, 100, 400
    sleep r
return

答案 1 :(得分:0)

或者这个:

Tab:: toggle := !toggle

#If toggle

~LButton::
while GetKeyState("LButton")
{
    Send {1}
    Random, r, 100, 400
    sleep r
}
return

#If