一个连续的 while 循环,通过热键 on/off 切换动作,与主体分开。我该如何处理?

A continuous while loop with actions toggled on/off by a hotkey, separate from the main body. How do I approach this?

我需要

while (true) {
   if (toggle) { ;(toggle is simply set on/off with a hotkey)
      ...stuff...
      Sleep, 250
   }
}

运行 独立于主“线程”,在本例中主“线程”卡在 RunWait

prev_volume := 20
SoundGet, prev_volume
if (prev_volume <= 32) {
    SoundSet, 26
}
RunWait, some game
SoundSet prev_volume
ExitApp

不确定如何处理这个问题

感谢任何帮助,提前致谢。

所以在这个实例中使用命令 SetTimer:

SetTimer, ToggleThingy, On ; defaults to 250 ms
toggle := false

prev_volume := 20
SoundGet, prev_volume
if (prev_volume <= 32) {
    SoundSet, 26
}
RunWait, some game
SoundSet prev_volume
ExitApp

{hotkey here}::
toggle := !toggle
Return


ToggleThingy:
if (toggle) { ;(toggle is simply set on/off with a hotkey)
    ...stuff...
    ; Sleep, 250 ; not needed because timer already runs every 250 ms
   }
}
Return ; needed to end the subroutine.