简体   繁体   中英

End continuous loop and restart script with same hotkey - AutoHotkey

I have this script below. It has a continuous loop in it.

I want to be able to: press the hotkey again (ie F4) and for the continuous loop to end, and for the script to restart .

I've tried using #MaxThreadsPerHotkey but have not had much luck. Anyone's help would be much appreciated. Thanks!

#MaxThreadsPerHotkey 10
F4::
Send, z
Sleep, 100
Send, ^{Left}
Loop,
{
Sleep, 30000
WinActivate, ahk_exe PotPlayerMini64.exe
Send, z
SoundBeep
}
Return

You can (and should) use timers instead of Sleep loops. This should work:

F4::
    Send, z
    Sleep, 100
    Send, ^{Left}
    SetTimer, SendLoop, 3000
Return

SendLoop:
    WinActivate, ahk_exe PotPlayerMini64.exe
    Send, z
    SoundBeep
Return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM