Snarg

Random clicks in a box

9 posts in this topic

#1 ·  Posted (edited)

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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

JohnOne means the Sciteconsole. F8 toggle status of the Sciteconsole Show<=>Hide. 

18 minutes ago, Snarg said:

I must be doing something wrong.

Show complete script.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Share this post


Link to post
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)?

Share this post


Link to post
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

  • Similar Content

    • hcI
      By hcI
      Hello everyone !
      I've made a little function who return random characters for everyone who would need it.. It's my first function so please have some mercy.
      And if you have some suggestions.. don't hesitate !
      and I made a AutoIt HelpFile that looks like others helpfiles, I hope you'll enjoy !
      The function :  RandomLetter.au3
      The helpfile : RandomLetter.html  (in HTML please !)
      Et pour les anglophobes, voilà l'aide en français : RandomLetter.fr.html (French version of the helpfile)
      Thanks, hcI
    • mazz3d
      By mazz3d
      hello  everyone,
      I'm new with AutoIT and just looking for a way to open Firefox with random window size
      i have tried too many different samples from the web, some how it works but i can't make it works with Firefox 
      MozRpel and ff.au3 installed 
      right now i can open Firefox with this code, but i still can't control the window of Firefox
      ; open firefox #include <ff.au3> _FFStart() ; open firefox with random size  
    • ZeroByDevide
      By ZeroByDevide
      i have this code running but it just would not start the code:
      Local $rndSleep = Int (Random(180000,240000,1000))
      MsgBox($MB_SYSTEMMODAL, "NaaaNuuu", "This message box will show the sleeptime after closing the tabs, you got " & $rndSleep & " seconds left.", $rndSleep)
       
      here is the error it shows me:
      "C:\Users\numan\Desktop\scipiie.au3" (23) : ==> Variable used without being declared.:
      MsgBox($MB_SYSTEMMODAL, "NaaaNuuu", "This message box will show the sleeptime after closing the tabs, you got " & $rndSleep & " seconds left.", $rndSleep)
      MsgBox(^ ERROR
    • TheDcoder
      By TheDcoder
      Hello!
      After watching a whole day of "Journey into cryptography" at Khan Academy, I have got to know the secrets behind some sneaky things! . This is one of em', A PRNG (Pseudo Random Number Generator). Its features (atleast what I believe) are:
      Simple, short and crappy. Great for beginners who are baffled by the mechanics of random number generation in computers! Support for custom seeds! EIGHT DIGITS OF RANDOMNESS!!! Unlike all other PRNGs, This one is predictable 1000 possible PRNs when using @MSEC as the seed. No option for min or max, the min is 10000000 and the max is 99999999. The Unlicensed . #cs LICENSE This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org/> #ce LICENSE ; #FUNCTION# ==================================================================================================================== ; Name ..........: MiddleSquareRandom ; Description ...: Pseudo-random number generator based on the infamous "Middle Sqaure" method. ; Syntax ........: MiddleSquareRandom([$iSeed = @MSEC]) ; Parameters ....: $iSeed - [optional] A seed for generation of the random number. Default is @MSEC. ; Return values .: A pseudorandom 8 digit integer. ; Author ........: John von Neumann ; Modified ......: Damon Harris (TheDcoder) - Conversion into AutoIt and simplification + further crappification. ; Remarks .......: Fun Fact - The output is based on the $iSeed passed, Same $iSeed = Same pseudo-random number. ; Related .......: Random() ; Link ..........: https://en.wikipedia.org/wiki/Middle-square_method ; Example .......: ConsoleWrite(MiddleSquareRandom() & @CRLF) ; =============================================================================================================================== Func MiddleSquareRandom($iSeed = @MSEC) Local Const $TURNS = 8 Local $sRandomNumber, $sSeed For $iTurn = 1 To $TURNS $iSeed = $iSeed * 2 $sSeed = String($iSeed) $sRandomNumber &= StringMid($sSeed, Ceiling(StringLen($iSeed) / 2), 1) Next Return Int($sRandomNumber) EndFunc  
      Enjoy your numbers, TD .
      P.S NEVER USE THIS FUNCTION IN A REAL WORLD IMPLEMENTATION OF SOMETHING WHICH USES RANDOM NUMBERS!!! THIS ONE IS VERY UNSUITABLE FOR THAT PURPOSE! READ THE POSTS BELOW FOR MORE INFORMATION.
    • cookiemonster
      By cookiemonster
      Hoping for some guidance, I have a string like:
      $string='vXx2586578£&' How can I go abouts shuffling the contents of the string?