Auto clicker when hotkey down

Ask gaming related questions (AHK v1.1 and older)
roofik5
Posts: 23
Joined: 03 Jan 2021, 10:52

Auto clicker when hotkey down

Post by roofik5 » 30 Nov 2021, 07:50

Hi everyone,
So I've tried my best to write my own hotkey, but for now I'm stucked.

What I want to do is that whenever Mbutton is clicked it's going to left click mouse as fast as it can but every 100 click it stops for a second. And whenever I take my finger off of Mbutton it stops.

As for now I have this code: and it works as I want to but after 100 clicks it does not go again to 200..300.. etc.
Could anyone help me with this?

Code: Select all

Process, Priority, , A
SetMouseDelay, -1
Mbutton::
Loop{
			Loop, 100 {
						If (GetKeyState("Mbutton","P")){
												Click
												}
						else{
							break
							}

					}
Sleep 500 
return
}
return
PgUp::
Pause::

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Auto clicker when hotkey down

Post by mikeyww » 30 Nov 2021, 08:53

Code: Select all

MButton::
While GetKeyState(A_ThisHotkey, "P") {
 Click
 Sleep, Mod(A_Index, 100) ? 0 : 1000
}
Return

roofik5
Posts: 23
Joined: 03 Jan 2021, 10:52

Re: Auto clicker when hotkey down

Post by roofik5 » 30 Nov 2021, 10:57

It works perfect!
But I'm not sure how. Is it ok if you explain it to me?
I will be thankful:)

User avatar
mikeyww
Posts: 26851
Joined: 09 Sep 2014, 18:38

Re: Auto clicker when hotkey down

Post by mikeyww » 30 Nov 2021, 11:21

The loop runs while the key is held. First, it clicks the left mouse button. Next, if the Mod, 100 is non-zero, it sleeps for 0 milliseconds; otherwise, it sleeps for 1000 ms. A_Index is the iteration number. The Mod is zero when the A_Index is 100, 200, 300, etc.

Explained: ModTernary operator

roofik5
Posts: 23
Joined: 03 Jan 2021, 10:52

Re: Auto clicker when hotkey down

Post by roofik5 » 30 Nov 2021, 12:58

You are really helpful. Thank you a lot

Post Reply

Return to “Gaming Help (v1)”