问题描述
所以我是AutoHotkey的新手,我在Multiloop计时器方面遇到了一些问题,它在第一个循环中工作正常,但在第二个循环中,时间与我想要的时间不匹配。
所以基本上我希望循环运行5分钟,loopTwo应该是7s之后的第一个循环,然后2秒后,我希望在loopOne中调用loopOne第一次按下之间有1.2s的延迟工作正常,但是时间开始改变,一切都陷入混乱
F1::
If (loopOne = True)
{
SetTimer loopTwo,Off
TwoSwitch := False
SetTimer loopOne,Off
Oneswitch := False
} else {
TheTwoTime := 0
SetTimer loopTwo,7000 ;run every 7s
TwoSwitch := True
TheOneTime := 0
SetTimer loopOne,9000 ;run every 9s
Oneswitch := True
}
return
loopOne:
Send,1
Sleep,1200
Send,1
TheOneTime ++
If TheOneTime >= 300 ;run for 5 minutes
{
SetTimer loopOne,Off
Oneswitch := False
}
return
loopTwo:
Send,2
Sleep,2000
TheTwoTime ++
If TheOneTime >= 300 ;run for 5 minutes
{
SetTimer loopTwo,Off
TwoSwitch := False
}
return
解决方法
我认为这就是您想要做的。假设我正确理解了您的情况,我认为不需要两个计时器。
由于它是首选的更快,更可靠的发送模式,因此也放弃了旧标签并切换到SendInput。
除了切换toggle:=!toggle
外,它应该是一个非常简单的脚本。如果您听不懂,就会看到我的一个老答案,它有点here。
还要注意在计时器中使用负周期,这是非常有用的事情。
F1::
if (toggle:=!toggle)
{
SetTimer,MyCoolLoop,7000 ;7sec period
SetTimer,StopLooping,-300000 ;negative period,run ONCE after 5mins
}
else
SetTimer,Off
return
MyCoolLoop()
{
;number 2 gets sent (every 7secs)
;2secs after this,number 1 gets sent
;1.2secs after this,number 1 gets sent again
;3.8secs after this,we start from the beginning
SendInput,2
Sleep,2000
SendInput,1
Sleep,1200
SendInput,1
}
StopLooping()
{
SetTimer,Off
}