0

I've only just started with AutoHotKey, and I'm looking to make a script that will click once per second 10 times, then hold right mouse button for 3 seconds, before resetting. I intend it to active on alt+c, and break if I press the left mouse button.

The script I came up with it

LButton::
BreakLoop = 1
return
!c::
Loop
{
if (BreakLoop = 1)
break
;

Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
Return
}

However, this is not working. Is there a way to fix this, or have I taken the completely wrong approach for this script?

3 Answers 3

1

You did make a Mistake in the code, On the Bottom You did have the Return Command into the Loop that is not possible. (This Return Command Will be needed for !c:: and it must outsite the loop command)

The Code must be Like:

~LButton::
BreakLoop = 1
return

!c::
Loop
{
if (BreakLoop = 1)
break

Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Click
Sleep, 1000
Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
}
Return

Tip: if you change Lbutton:: into ~Lbutton:: then The Default LeftButton is also active.

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

1 Comment

Yep, shifting the return outside the loop fixed it! I also changed my break key, as I was using my mouse button before I'd activate it by accident.
0

I was actually able to find a way to compact it significantly (and break the loop faster) by nesting a loop within a loop

!s::
BreakLoop = 1
return


!c::
BreakLoop = 0

Loop
{

Loop 10
{
if (BreakLoop = 1)
break
;
Click
Sleep, 900
}

Send, {RButton Down}
Sleep, 3000
Send, {RButton Up}
}
if (BreakLoop = 1)
Break
;

Return

Comments

0

A better method is to use SetTimer, this allows you to break out of the loop at any point in your sequence of actions.

Try:

!c::setTimer, doAction, 1000
!s::SetTimer, doAction, Off 

doAction:
    i += (i <= 14 ? 1 : -13)
    if (i == 14)
        send, {RButton Up}
    else if (i == 11 )
        Send, {RButton Down}
    else if (i <= 10) 
        click   
return

Comments

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.