1

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 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't test this right now, but this old answer of mine seems to be nonsense: the x hotkey spawns a new thread that just goes to after_loop and then stops again. It does not change the other thread of w:: which will keep running regardless of the other one... Instead, a variable should be set in x and w should break based on that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.