Help with my AutoClicker Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
HKUK01
Posts: 7
Joined: 18 Jun 2018, 12:48

Help with my AutoClicker

Hey, I'm a beginner and I've been looking for a code which can click on a random position within a range of set coordinates and sleep for a random amount of time within a range of time. The code I made only clicks on a specific coordinate and sleeps for a specific time.

f1::
MouseClick , Left , 10 , 19
sleep 600
MouseClick , Left , 565 , 180
sleep 600
MouseClick , Left , 289 , 199
sleep 600

Any help will be greatly appreciated.
DyaTactic
Posts: 191
Joined: 04 Apr 2017, 05:52

Re: Help with my AutoClicker

Use the Random function to generate a random number.

Code: Select all

``````Random, OutputVar, Min, Max
``````
Let me know if you have any more questions.
swagfag
Posts: 3624
Joined: 11 Jan 2017, 17:59

Re: Help with my AutoClicker  Topic is solved

wrap random in a function, then define another function for clicking, sleep accepts expressions, so it can be used as is, in conjunction with your wrapped random function

Code: Select all

``````q::
randClick(1, 1, 20, 20)
Sleep rand(300, 1000)
randClick(1, 1, 20, 20)
Return

rand(min, max) {
Random, rand, min, max
return rand
}

randClick(x1, y1, x2, y2) {
x := rand(x1, x2)
y := rand(y1, y2)
Click %x%, %y%
}``````
HKUK01
Posts: 7
Joined: 18 Jun 2018, 12:48

Re: Help with my AutoClicker

swagfag wrote:wrap random in a function, then define another function for clicking, sleep accepts expressions, so it can be used as is, in conjunction with your wrapped random function

Code: Select all

``````q::
randClick(1, 1, 20, 20)
Sleep rand(300, 1000)
randClick(1, 1, 20, 20)
Return

rand(min, max) {
Random, rand, min, max
return rand
}

randClick(x1, y1, x2, y2) {
x := rand(x1, x2)
y := rand(y1, y2)
Click %x%, %y%
}``````
Hey, thanks for replying, I used your code below and it works great but I don't know what I'm doing wrong because on 'click 3' which I've added it doesn't seem to click on the right co-ordinate. Also how would I loop this entire code for a specific number of times? Thanks.

Code: Select all

``````q::
randClick(0, 0, 80, 80) ;click1
Sleep rand(300, 1000)
randClick(680, 1040, 730, 1060) ;click2
Sleep rand(300, 1000)
randClick(890, 100, 900, 110) ;click3
Return

rand(min, max) {
Random, rand, min, max
return rand
}

randClick(x1, y1, x2, y2) {
x := rand(x1, x2)
y := rand(y1, y2)
Click %x%, %y%
}
``````
HKUK01
Posts: 7
Joined: 18 Jun 2018, 12:48

Re: Help with my AutoClicker

DyaTactic wrote:Use the Random function to generate a random number.

Code: Select all

``````Random, OutputVar, Min, Max
``````
Let me know if you have any more questions.
Hey, thanks for replying, I've implemented the random function into the code but was wondering how I would loop this entire code below for a specific number of times. Also 'click 3' doesn't seem to click on to the correct co-ordinate. Thanks.

Code: Select all

``````q::
randClick(0, 0, 80, 80) ;click1
Sleep rand(300, 1000)
randClick(680, 1040, 730, 1060) ;click2
Sleep rand(300, 1000)
randClick(890, 100, 900, 110) ;click3
Return

rand(min, max) {
Random, rand, min, max
return rand
}

randClick(x1, y1, x2, y2) {
x := rand(x1, x2)
y := rand(y1, y2)
Click %x%, %y%
}``````
swagfag
Posts: 3624
Joined: 11 Jan 2017, 17:59

Re: Help with my AutoClicker

check the CoordMode function and select a mode accordingly.
DyaTactic
Posts: 191
Joined: 04 Apr 2017, 05:52

Re: Help with my AutoClicker

Looping like this?

Code: Select all

``````q::
Loop, 3	; Repeat 3 times.
{
randClick(0, 0, 80, 80) ;click1
Sleep rand(300, 1000)
randClick(680, 1040, 730, 1060) ;click2
Sleep rand(300, 1000)
randClick(890, 100, 900, 110) ;click3
}
Return
``````
HKUK01
Posts: 7
Joined: 18 Jun 2018, 12:48

Re: Help with my AutoClicker

DyaTactic wrote:Looping like this?

Code: Select all

``````q::
Loop, 3	; Repeat 3 times.
{
randClick(0, 0, 80, 80) ;click1
Sleep rand(300, 1000)
randClick(680, 1040, 730, 1060) ;click2
Sleep rand(300, 1000)
randClick(890, 100, 900, 110) ;click3
}
Return
``````
Yup that works fine and I figured out the problem with click 3 thanks a lot for the help.
DyaTactic
Posts: 191
Joined: 04 Apr 2017, 05:52

Re: Help with my AutoClicker

You're most welcome