AutoHotKey keystroke break loop

Dave picture Dave · Apr 25, 2013 · Viewed 7.7k times · Source

Using AutoHotKey, I have a rather simple loop script that I want to be able to break by the stroke of a key. I tried a few different codes from websites but it doesn't seem to work.

Here's the code:

#g::
Loop 20
{
    MouseClick, left,  142,  542
    Sleep, 1000
    MouseClick, left,  138,  567
    Sleep, 1500
    MouseClick, left,  97,  538 
    Sleep, 1000
}

Answer

user6687019 picture user6687019 · Aug 7, 2016

Use a global variable (keepCycling) and toggle it to break the loop. Global variables should be declared in the beginning of a script.