Jump to content
Sign in to follow this  
Snarg

Random clicks in a box

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.

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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Garrik
      Hi guys!
       
      I need some help here, is there a way to use Random with While? 
      I need this script to run in between 1 and 4 times but I dont know how to do it, can you please help me?
       
      dim $i=1
      While $i<=4
      Sleep(3000)
      Send("{LWINDOWN}r{LWINUP}")
      Sleep(3000)
      Send("C:\Users\123\Catalogos\tags.txt{ENTER}")
      Sleep(3000)
      WinActivate("tags: Bloc de notas","")
      Sleep(3000)
      Send("{SHIFTDOWN}{END}{SHIFTUP}{CTRLDOWN}c{CTRLUP}{DEL}{DEL}")
      Sleep(3000)
      Send("{CTRLDOWN}g{CTRLUP}{ALTDOWN}{F4}{ALTUP}")
      Sleep(3000)
      Send("{CTRLDOWN}v{CTRLUP}{SPACE}")
      $i=$i+1
      WEnd
    • By Inpho
      Hi All,
      I intend on keeping custom functions/UDFs (works in progress) here; if anyone wants to use any code, feel free.
      String functions:
      #AutoIt3Wrapper_AU3Check_Parameters=-d -w- 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _DateTimeGet ; Description ...: Returns the date and time formatted for use in sortable filenames, logs, listviews, etc. ; Syntax ........: _DateTimeGet(iType = 1[, $bHumanFormat = False]) ; Parameters ....: $iType - [optional] an integer value. Default is 1. ; 1 - Date and time in file-friendly format; 20190115_113756 ; 2 - Date in file-friendly format; 20190115 ; 3 - Time in file friendly format; 113756 ; $bHumanFormat - [optional] a boolean value. Default is False. ; True - Includes slashes in the date and colons in the time with a space inbetween ; False - No slashes or colons included with an underscore inbetween ; Return values .: Success - String ; Failure - Sets @error to non-zero and returns an empty string ; Author ........: Sam Coates ; =============================================================================================================================== Func _DateTimeGet($iType = 1, $bHumanFormat = False) If $iType < 1 Or $iType > 3 Then Return (SetError(-1, 0, "")) ;; Param1: ;; 1 = Date and time in file friendly format: 20190115_113756 ;; 2 = Date in file friendly format: 20190115 ;; 3 = Time in file friendly format: 113756 ;; Param2: ;; True = Use human-readable format: 15/01/2019 11:37:56 Local $sTime = @HOUR & ":" & @MIN & ":" & @SEC Local $sDate = @MDAY & "/" & @MON & "/" & @YEAR If $iType = 1 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, ":", "") $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) Return ($sDate & "_" & $sTime) Else Return ($sDate & " " & $sTime) EndIf ElseIf $iType = 2 Then If $bHumanFormat = False Then $sDate = StringReplace($sDate, "/", "") $sDate = StringTrimLeft($sDate, 4) & StringMid($sDate, 3, 2) & StringLeft($sDate, 2) EndIf Return ($sDate) ElseIf $iType = 3 Then If $bHumanFormat = False Then $sTime = StringReplace($sTime, "/", "") EndIf Return ($sTime) EndIf EndFunc ;==>_DateTimeGet ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileExtension ; Description ...: Returns a file extension from a filename/FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileExtension($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileExtension($sPath) Return (StringTrimLeft($sPath, StringInStr($sPath, ".", 0, -1))) EndFunc ;==>_FileToFileExtension ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFileName ; Description ...: Returns a filename from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFileName($sPath[, $bIncludeExtension = True]) ; Parameters ....: $sPath - a string value. ; $bIncludeExtension - [optional] a boolean value. Default is True. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFileName($sPath, $bIncludeExtension = True) Local $sReturn = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) If $bIncludeExtension = False Then $sReturn = StringLeft($sReturn, StringInStr($sReturn, ".", 0, -1) - 1) Return ($sReturn) EndFunc ;==>_FileToFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _FileToFilePath ; Description ...: Returns a folder path from a FQPN (Fully Qualified Path Name) ; Syntax ........: _FileToFilePath($sPath) ; Parameters ....: $sPath - a string value. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _FileToFilePath($sPath) Return (StringLeft($sPath, StringInStr($sPath, "\", 0, -1) - 1)) EndFunc ;==>_FileToFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringLeft ; Description ...: Searches for a string inside a string, then removes everything on the right of that string ; Syntax ........: _StringLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) - 1)) EndFunc ;==>_StringLeft ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringRandom ; Description ...: Returns a string of random characters ; Syntax ........: _StringRandom($iAmount[, $iType = 1]) ; Parameters ....: $iAmount - an integer value. Length of returned string ; $iType - [optional] an integer value. Default is 1. ; 1 - Return digits (0-9) ; 2 - Return hexadecimal (0-9, A - F) ; 3 - Return Alphanumeric upper (0-9, A - Z) ; 4 - Return Alphanumeric (0-9, A - Z, a - z) ; 5 - Return Alpha upper (A - Z) ; 6 - Return Alpha (A - Z, a - z) ; Return values .: Success - String ; Failure - Empty string and @error flag as follows: ; @error : 1 - $iAmount is not a positive integer ; 2 - $iType is out of bounds ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringRandom($iAmount, $iType = 1) If $iAmount < 1 Or IsInt($iAmount) = 0 Then Return (SetError(-1, 0, "")) Local $sString = "" Local $iRandomLow = 1, $iRandomHigh = 62 #Tidy_Off Local Static $aCharId[63] = [0, Chr(48), Chr(49), Chr(50), Chr(51), Chr(52), Chr(53), Chr(54), Chr(55), Chr(56), Chr(57), Chr(65), Chr(66), Chr(67), _ Chr(68), Chr(69), Chr(70), Chr(71), Chr(72), Chr(73), Chr(74), Chr(75), Chr(76), Chr(77), Chr(78), Chr(79), Chr(80), _ Chr(81), Chr(82), Chr(83), Chr(84), Chr(85), Chr(86), Chr(87), Chr(88), Chr(89), Chr(90), Chr(97), Chr(98), Chr(99), _ Chr(100), Chr(101), Chr(102), Chr(103), Chr(104), Chr(105), Chr(106), Chr(107), Chr(108), Chr(109), Chr(110), Chr(111), _ Chr(112), Chr(113), Chr(114), Chr(115), Chr(116), Chr(117), Chr(118), Chr(119), Chr(120), Chr(121), Chr(122)] #Tidy_On If $iType = 1 Then ;; digits: 1 - 10 $iRandomHigh = 10 ElseIf $iType = 2 Then ;; hexadecimal: 1 - 16 $iRandomHigh = 16 ElseIf $iType = 3 Then ;; alnumupper: 1 - 36 $iRandomHigh = 36 ElseIf $iType = 4 Then ;; alnum: 1 - 62 $iRandomHigh = 62 ElseIf $iType = 5 Then ;; alphaupper: 11 - 36 $iRandomLow = 11 $iRandomHigh = 36 ElseIf $iType = 6 Then ;; alpha: 11 = 62 $iRandomLow = 11 $iRandomHigh = 62 Else Return (SetError(-2, 0, "")) EndIf For $i = 1 To $iAmount $sString &= $aCharId[Random($iRandomLow, $iRandomHigh, 1)] ;; append string with corresponding random character from ascii array Next Return ($sString) EndFunc ;==>_StringRandom ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringTrimLeft ; Description ...: Searches for a string inside a string, then removes everything on the left of that string ; Syntax ........: _StringTrimLeft($sString, $sRemove[, $iCaseSense = 0, $iOccurrence = 1]) ; Parameters ....: $sString - a string value. The string to search inside. ; $sRemove - a string value. The string to search for. ; $iCaseSense - an integer value. Flag to indicate if the operations should be case sensitive. ; $iOccurrence - an integer value. Which occurrence of the substring to find in the string. Use a ; negative occurrence to search from the right side. ; Return values .: Success - String ; Failure - Empty string as returned from StringTrimLeft() ; Author ........: Sam Coates ; =============================================================================================================================== Func _StringTrimLeft($sString, $sRemove, $iCaseSense = 0, $iOccurrence = 1) Return (StringTrimLeft($sString, StringInStr($sString, $sRemove, $iCaseSense, $iOccurrence) + StringLen($sRemove) - 1)) EndFunc ;==>_StringTrimLeft Examples:
      ConsoleWrite(_StringRandom(100, 6) & @CRLF) ConsoleWrite(_StringTrimLeft("C:\Windows\System32\cmd.exe", "C:\Windows\System32\") & @CRLF) ConsoleWrite(_StringLeft("C:\Windows\System32\cmd.exe", "cmd.exe") & @CRLF) ConsoleWrite(_FileToFileName("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFilePath("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_FileToFileExtension("C:\Windows\System32\cmd.exe") & @CRLF) ConsoleWrite(_StringRandom(6, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(4, 4) & "-" & _StringRandom(6, 4)& @CRLF)  
    • By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • By Anas
      Hi,
      I've this script (removed unrelated parts) that generate a set of random chars for a password. It gets launched from a network share by Task Scheduler at a specific time for all PC's, then it relaunches itself from the local drive.
       
      Global $LocalToolsDir = @ProgramFilesDir & '\Tools' Start() Func Start() If Not StringInStr(@ScriptFullPath, $LocalToolsDir, 2) Then Exit RunLocaly() Sleep(Random(1, 1800, 1) * 1000) $NewPass = GeneratePass() EndFunc Func GeneratePass() Local $Pass For $i = 1 to 8 $R = Random(0,1.5) If $R > 1 Then $Chr = Random(0,9,1) ElseIf $R < 0.5 Then $Chr = Chr(Random(Asc("A"), Asc("Z"), 1)) Else $Chr = Chr(Random(Asc("a"), Asc("z"), 1)) Endif $Pass &= $Chr Next Return $Pass EndFunc Func RunLocaly() Local $Run = 1, $LocalApp = $LocalToolsDir & '\' & @ScriptName If Not FileExists($LocalApp) Then $Run = FileCopy(@ScriptFullPath, $LocalToolsDir, 1 + 8) If $Run Then Run($LocalApp, $LocalToolsDir) EndFunc  
      The problem is that many PC's ends up with the same password(s).
      e.g. 10 PC's have (abc123) as a Password, and another 10 have this (def456)
      Any idea why?
    • By Dequality
      Got a simple question is it possible to have lets say 10 functions and use the random function to randomly pick one of them? If so could anyone please make a tiny example?
       
      Tyvm in advance 
      -Dequality
×
×
  • Create New...