1
votes

Whenever you press w you get into a loop that press e around every 10 seconds. Another button has to be pressed to get out of it again at any moment (and making it possible to start over again). This is what I have so far:

w::
Loop
{
Send, e
Random, SleepAmount, 9000, 10000
Sleep, %SleepAmount%
x::Break
}
Return  

I don't understand why it is not working yet. It presses e once and doesn't do anything anymore after that.

1

1 Answers

2
votes
x::Break

is the short form for

x::
    break
return

and therefore terminates the current subroutine. Never define a hotkey within any other execution bodies. Instead, define the x-hotkey outside the w hotkey and make it stop the loop.

Example using goTo (note that goSub is different for the latter will not terminate the subroutine):

w::
    Loop {
        send e
        Random, SleepAmount, 9000, 10000
        Sleep, %SleepAmount%
    }
    after_loop:
return

x::
    goTo after_loop
return
; or, more compact:
; x::goto after_loop

Since gotos are pretty bad programming style, you might consider using a timer (instead of the loop). But to be honest, it's not worth it because your sleep amount is not fix.