如何暂停主循环并每分钟按一下buff键?但主循环autohotkey脚本似乎覆盖了两个计时器脚本同时运行?如何使主循环暂停并使计时器的优先级每隔一分钟运行按键?
home::
SetTimer, skillbuffs, 60000 ;1min
loop
{
;attack loop and pick items main script
}
skillbuffs:
send{f5} ;press self skill every1min
SetTimer, skillbuffs, On
return
答案 0 :(得分:0)
SetTimer
与脚本的其余部分并行运行其任务,这就是您没有看到循环等待的原因。
你可以在定时器中包含循环,这会强制它在完成任务之前等待循环中断,例如下面的代码:
DoTheLoop()
{
StartTime := A_TickCount ; Set current tick time (uptime of PC) to compare against.
loop
{
ElapsedTime := A_TickCount - StartTime ; Difference between start of loop and now.
SendInput, %ElapsedTime%{Enter}
Sleep, 1000
if ( ElapsedTime >= 10000 ) ; 10.0 sec.
{
break
}
}}
Home::
SetTimer, skillbuffs
skillbuffs:
DoTheLoop()
SendInput, Skillbuffs timer has fired.{Enter}
SetTimer, skillbuffs, On
return
但这至多是一种kludge,因此并非100%可靠。除此之外,如果您有明确定义的任务和时间框架,那么您似乎过度设计了问题。
相反,我建议更简单:
MainLoop()
{
StartTime := A_TickCount ; Set current tick time (uptime of PC) to compare against.
loop
{
ElapsedTime := A_TickCount - StartTime ; Difference between start of loop and now.
; Do stuff in the loop.
if ( ElapsedTime >= 60000 ) ; 60.0 sec.
{
SendInput, {F5} ; Press self skill every 60 sec.
StartTime := A_TickCount ; Reset StartTime variable.
}
}}
Home::
MainLoop()
return
答案 1 :(得分:-1)
在主循环中的某处添加Sleep, 10
(或100,或任何您认为可以负担的持续时间)。这将暂停主循环数毫秒,允许其他进程获得运行时间。如果代码标记为Critical
,这可能尤为重要。