Jump to content

Random clicks in a box


 Share

Recommended Posts

Hello,

 

I am attempting to build a script that will click randomly inside of a box. The box dimensions, number of clicks, and the delay between the clicks is passed to a function. I feel a am very close to finishing this script, but could use a bit of help.

 

I am passing the function four different boxes, two of them to be clicked 18 times, one of them twice and one of them three times. This is repeated four times. The problem I am having is with the first box. It only clicks that box 17 times. It then completes the next three boxes. Once the last box is complete, it does the last click on the first box.

 

I have worked this problem for the past two days now and can not see where I have gone wrong. Any help anyone would be able to provide with this issue would be greatly appreciated. Thank you for your time. The code is below:

 

Opt ("MouseCoordMode", 2)
Opt ("MouseClickDelay", 0)

HotKeySet ("{ESC}", "Terminate")
HotKeySet ("+{F9}", "SelectBox")

While 1
   Sleep (100)
WEnd

Func SelectBox ()

   ;Stuff happens here
      ClickBox ()
   ;Stuff happens here

EndFunc   ;==>SelectBox

Func ClickBox ()

   _MouseClick (431, 271, 477, 311, 18, 50, 100) ;Cick 18 times

   _MouseClick (317, 272, 385, 306, 18, 50, 100) ;Cick 18 times

   _MouseClick (683, 267, 749, 306, 2, 50, 100) ;Cick 2 times

   _MouseClick (504, 267, 568, 306, 3, 50, 100) ;Cick 3 times

EndFunc   ;==>ClickBox

;$tlx - top left x
;$tly - top left y
;$blx - bottom right x
;$bly - bottom right y
;Numclicks - number of clicks
;$sl1 - sleep low delay
;$sl2 - sleep high delay
Func _MouseClick ($tlx, $tly, $brx, $bry, $Numclicks, $sl1, $sl2)
   Dim $box[4] = [$tlx, $tly, $brx, $bry]
   For $Count = 1 to $Numclicks
      MouseMove(Random($box[0], $box[2]), Random($box[1], $box[3]), 0)
      MouseClick ("left")
      _Sleep ($sl1, $sl2)
   Next
EndFunc ;==>_MouseClick

Func _Sleep ($min, $max)
   Sleep (Random ($min, $max, 1))
EndFunc ;==>_Sleep

Func Terminate()
   Exit
EndFunc   ;==>Terminate

 

Edited by Snarg

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

Does not look like there is anything wrong.

what is output?

Func _MouseClick ($tlx, $tly, $brx, $bry, $Numclicks, $sl1, $sl2)
   Dim $box[4] = [$tlx, $tly, $brx, $bry]
   ConsoleWrite("Clicking " & $Numclicks & " times" & @LF)
   For $Count = 1 to $Numclicks
      MouseMove(Random($box[0], $box[2]), Random($box[1], $box[3]), 0)
      MouseClick ("left")
      ConsoleWrite($Count & " ")
      _Sleep ($sl1, $sl2)
   Next
   ConsoleWrite(@LF)
EndFunc ;==>_MouseClick

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thank you JohnOne for trying to help. For whatever reason the console window does not open when the script runs. I must be doing something wrong.

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

AutoBert, thank you for the reply. I have opened the console window in Scite, but don't really understand how to pipe the output to that.

 

That pretty much is the full script. I'm trying to get that section to work before I do anything else with it.

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

Here is the output:

 

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Clicking 2 times
1 2

Clicking 3 times
1 2 3

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Clicking 2 times
1 2
Clicking 3 times
1 2 3

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 2 times
1 2
Clicking 3 times
1 2 3

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 18 times
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Clicking 2 times
1 2
Clicking 3 times
1 2 3

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

It's clicking the correct number of times. How would I go about getting it to display the coordinates it is clicking?

Edited by Snarg

A little reading goes a long way. Post count means nothing.

Link to comment
Share on other sites

Func _MouseClick ($tlx, $tly, $brx, $bry, $Numclicks, $sl1, $sl2)
   Dim $box[4] = [$tlx, $tly, $brx, $bry]
   ConsoleWrite("Clicking " & $Numclicks & " times" & @LF)
   For $Count = 1 to $Numclicks
      $RandomMousePosX = Random($box[0], $box[2])
      $RandomMousePosY = Random($box[1], $box[3])
      MouseMove($RandomMousePosX, $RandomMousePosY, 0)
      MouseClick ("left")
      ConsoleWrite("Click number: " & $Count & " | Mouse PosX: " & $RandomMousePosX & " | Mouse PosY: " & $RandomMousePosY & @CRLF)
      _Sleep ($sl1, $sl2)
   Next
   ConsoleWrite(@LF)
EndFunc ;==>_MouseClick

Not tested. Why not MouseClick("left", $RandomMousePosX, $RandomMousePosY, 1, 0)?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...