# Is this done correctly?

## 6 posts in this topic

#1 ·  Posted (edited)

What i have done is set Coordinates in xyBox1, xyBox2 and xyBox5 (with MouseGetPos() - The rest of my code works 100%)

And instead of going out every time and entering every single box coordinate i figured i would come up with this "Formula" to calculate all the boxes locations by itself from what i have entered for my 3 Variables

Everytime i run, it clicks on box 1, 2, 5, 6 and the crashes, skips box 3 and 4

Any Clue?

```Func FourxSeven()

; 0 Returns the X1 co-ordinate as an integer.

; 1 Returns the Y1 co-ordinate as an integer.

Local \$xSD = (\$xyBox1[1] - \$xyBox2[1]) ; (Box1 y - Box2 y) = xAxis - Sideways difference
Local \$yDD = (\$xyBox1[0] - \$xyBox5[0]) ; (Box1 x - Box5 x) = yAxis - Downwards Difference

MouseClick("Left", \$xyBox1[0], \$xyBox1[1]) ;#1 Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], \$xyBox1[1]) ;#2 Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD), \$xyBox1[1]) ;#3  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2)), \$xyBox1[1]) ;#4  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], \$xyBox5[1]) ;#5  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], \$xyBox5[1]) ;#6  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], \$xyBox5[1]) ;#7  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2))[0], \$xyBox5[1]) ;#8  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], (\$xyBox5[1] + \$yDD)[1]) ;#9  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], (\$xyBox5[1] + \$yDD))[1]) ;#10  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], (\$xyBox5[1] + \$yDD)[1]) ;#11  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2))[0], (\$xyBox5[1] + \$yDD)[1]) ;#12  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], (\$xyBox5[1] + (\$yDD * 2))[1]) ;#13  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], (\$xyBox5[1] + (\$yDD * 2))[1]) ;#14  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], (\$xyBox5[1] + (\$yDD * 2))[1]) ;#15  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2))[0], (\$xyBox5[1] + (\$yDD * 2))[1]) ;#16  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], (\$xyBox5[1] + (\$yDD * 3))[1]) ;#17  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], (\$xyBox5[1] + (\$yDD * 3))[1]) ;#18  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], (\$xyBox5[1] + (\$yDD * 3))[1]) ;#19  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2)[0], (\$xyBox5[1] + (\$yDD * 3))[1]) ;#20  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], (\$xyBox5[1] + (\$yDD * 4))[1]) ;#21  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], (\$xyBox5[1] + (\$yDD * 4))[1]) ;#22  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], (\$xyBox5[1] + (\$yDD * 4))[1]) ;#23  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2)[0], (\$xyBox5[1] + (\$yDD * 4))[1]) ;#24  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox1[0], (\$xyBox5[1] + (\$yDD * 5))[1]) ;#25  Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", \$xyBox2[0], (\$xyBox5[1] + (\$yDD * 5))[1]) ;#26 Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + \$xSD)[0], (\$xyBox5[1] + (\$yDD * 5))[1]) ;#27 Box Locations
Sleep(Random(590,1390,1))

MouseClick("Left", (\$xyBox2[0] + (\$xSD * 2))[0], (\$xyBox5[1] + (\$yDD * 5))[1]) ;#28 Box Locations
Sleep(Random(590,1390,1))

Sleep(Random(990, 1990, 1))

EndFunc```

Edited by K3STROS
Explaining

##### Share on other sites

Can you share the website with the boxes so we can test this?

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

##### Share on other sites

There isn't a website, it's a rectangle containing 28 squares in total, 4X7 But there is a distance between all of the squares depending on your screen resolution. So the equations I created should work. Its when I use them with MouseClick( )  and try to multiply my variables is where I think I went wrong.

##### Share on other sites

.And where is the download for the local app which shows the 28 squares? Whithout testing nobody can say "Good work done"! The random sleeps are typicaly for online game bot's to simulate a human player.

##### Share on other sites

....

```....
Local \$xSD = (\$xyBox1[1] - \$xyBox2[1]) ; (Box1 y - Box2 y) = xAxis - Sideways difference
Local \$yDD = (\$xyBox1[0] - \$xyBox5[0]) ; (Box1 x - Box5 x) = yAxis - Downwards Difference

....```

Logically, the above should be replaced with the following. So that the difference in 'x' values relate to the horizontal X-axis. and,  difference in 'y' values relate to the vertical Y-axis.

```Local \$xSD = (\$xyBox1[0] - \$xyBox2[0]) ; (Box1 x - Box2 x) = xAxis - Sideways difference
Local \$yDD = (\$xyBox1[1] - \$xyBox5[1]) ; (Box1 y - Box5 y) = yAxis - Downwards Difference```

Knowing all those MouseClick's could be replaced with one MouseClick in a loop with the appropriate formulas for "x" and "y", I produced this example.
Note: The _GDIPlus_GraphicsFillRect function is used only to help imagine the positions of the rectangles or squares.

```#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3>
#include <ButtonConstants.au3>

; https://www.autoitscript.com/forum/topic/178272-is-this-done-correctly/?do=findComment&comment=1279171
Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

_DrawColsxRows_WidthxDepthRects(4, 7, 10, 10, 140, 100, 10)

Func _DrawColsxRows_WidthxDepthRects(\$iNumCols, \$iNumRows, \$iRectWidth = 10, \$iRectDepth = 10, \$iXBorder = 10, \$iYBorder = 10, \$iSpacing = 2)
Local \$hGUI, \$hGraphic, \$curBrush, \$x, \$y, \$msg, \$iIndex, \$aMPos, \$xSquarePos, \$ySquarePos, \$idBut, \$iCount = 0, \$Flag = 0
\$hGUI = GUICreate(\$iNumCols & "x" & \$iNumRows & " Squares of Size: " & \$iRectWidth & "x" & \$iRectDepth, 400, 400, -1, \$WS_EX_TOPMOST)
\$idBut = GUICtrlCreateButton("MouseClick all Rectangles", 125, 375, 150, 20) ;, \$BS_NOTIFY)
GUISetState(@SW_SHOW)

_GDIPlus_Startup()
\$hGraphic = _GDIPlus_GraphicsCreateFromHWND(\$hGUI)
\$curBrush = _GDIPlus_BrushCreateSolid("0xFF00FF00")
Do
For \$i = 0 To (\$iNumCols * \$iNumRows) - 1
\$x = \$iXBorder + ((\$iRectWidth + \$iSpacing) * Mod(\$i, \$iNumCols))
\$y = \$iYBorder + ((\$iRectDepth + \$iSpacing) * Int(\$i / \$iNumCols))
;ConsoleWrite(\$i & "  " & \$x & "  " & \$y & "  "  & @LF)
_GDIPlus_GraphicsFillRect(\$hGraphic, \$x, \$y, \$iRectWidth, \$iRectDepth, \$curBrush); Fill rectangles (squares)
\$msg = GUIGetMsg()
If \$msg = \$GUI_EVENT_CLOSE Then ExitLoop 2 ; Exits 2 loops, For-Next and Do-Until loops.
If (\$msg = \$GUI_EVENT_PRIMARYUP And \$Flag = 0) Or (\$Flag = 1 And \$msg = \$GUI_EVENT_MOUSEMOVE) Then
\$aMPos = MouseGetPos()
\$xSquarePos = Floor((\$aMPos[0] - \$iXBorder) / (\$iRectWidth + \$iSpacing))
\$ySquarePos = Int((\$aMPos[1] - \$iYBorder) / (\$iRectDepth + \$iSpacing))
\$iIndex = \$xSquarePos + (\$ySquarePos * \$iNumCols)
If (\$aMPos[0] >= \$iXBorder And (\$xSquarePos < \$iNumCols) And (\$aMPos[0] <= ((\$xSquarePos + 1) * (\$iRectWidth + \$iSpacing)) + \$iXBorder - \$iSpacing)) And _
(\$aMPos[1] >= \$iYBorder And (\$aMPos[1] <= ((\$ySquarePos + 1) * (\$iRectDepth + \$iSpacing)) + \$iYBorder - \$iSpacing)) And _
\$iIndex < \$iNumCols * \$iNumRows Then
MsgBox(0, \$iRectWidth & "x" & \$iRectDepth & _
" Square Info (Click a Square)", "Mouse Position X, Y: " & \$aMPos[0] & ", " & \$aMPos[1] & @CRLF & _
"Square Number along X-axis (0-based): " & \$xSquarePos & @CRLF & _
"Square Number along Y-axis (0-based): " & \$ySquarePos & @CRLF & _
"Rectangle index number     (0-based): " & \$iIndex, 2, \$hGUI)
EndIf
EndIf
If \$msg = \$idBut Then \$Flag = 1
Next

If \$Flag = 1 Then
WinActivate(\$iNumCols & "x" & \$iNumRows & " Squares of Size: " & \$iRectWidth & "x" & \$iRectDepth)
WinWaitActive(\$iNumCols & "x" & \$iNumRows & " Squares of Size: " & \$iRectWidth & "x" & \$iRectDepth)

MouseClick("left", \$iXBorder + \$iRectWidth / 2 + Mod(\$iCount, \$iNumCols) * (\$iRectWidth + \$iSpacing), _
\$iYBorder + \$iRectDepth / 2 + Int(\$iCount / \$iNumCols) * (\$iRectDepth + \$iSpacing), 1)
Sleep(30) ; Sleep(Random(590,1390,1))
\$iCount += 1
EndIf

If \$iCount > \$iNumCols * \$iNumRows Then
\$Flag = 0
\$iCount = 0
EndIf
Until 0

; Clean up resources
_GDIPlus_BrushDispose(\$curBrush)
_GDIPlus_GraphicsDispose(\$hGraphic)
_GDIPlus_Shutdown()
EndFunc   ;==>_DrawColsxRows_WidthxDepthRects```

##### Share on other sites

Oh wow.. That was such little mistake! But none the less thank you vury much appreciate it! I'm quite new to this and what you posted after makes little sense to me. I will study it though so thank you again for that! You're awesome!

## Create an account

Register a new account

• ### Similar Content

• By BJJ
Hello everyone,
I have huge problem with "Recurison level has been exceeded - AutoIt will quit to prevent stack overflow" in my own Bot.
I have no idea how rebuild my loops for eliminate this type of error.

Here is my code

• By jonson1986
Hey I searched code on autoit forum and modify it according to my needs and try to translate text from Russian to English in return I'm getting error such as "Error 411 (Length Required)!!1"
Both my autoit codes and error I got are given below, please help me to solve this issue, Thanks
Autoit codes to translate text form Russian to English;
#include <urlencode.au3> \$File1 = @ScriptDir & "\russian_text.txt" \$txt = FileRead(\$File1) ; Try to convert line breaks with .....so final URL looks simpler \$txt = StringReplace(\$txt, @CRLF, '...........') \$txt = StringReplace(\$txt, @LF, '.............') \$txt = StringReplace(\$txt, @CR, '.............') FileWrite (@scriptdir & '\russian_text2.txt', \$txt) \$openfile = @ScriptDir & "\russian_text2.txt" \$mytext = FileRead (\$openfile) \$encoding = urlencode (\$mytext) FileWrite (@scriptdir & '\enooding.txt', \$encoding) \$from = "ru" \$to = "en" \$url = "https://translate.googleapis.com/translate_a/single?client=gtx" \$url &= "&sl=" & \$from & "&tl=" & \$to & "&dt=t&q=" & \$encoding \$oHTTP = ObjCreate("Microsoft.XMLHTTP") \$oHTTP.Open("POST", \$url, False) \$oHTTP.Send() \$sData = \$oHTTP.ResponseText \$sData = StringRegExpReplace(\$sData, '.*?\["(.*?)(?<!\\)"[^\[]*', "\$1" & @crlf) FileWrite (@scriptdir & '\errorcode.txt', \$sData) Msgbox(0,"", \$sData) In response of above codes, I'm getting below error;

• By Masum
Hi all,
I'm facing a random error, whereby the ExcelRangeRead function is storing the first letter of a string as a lowercase rather than the uppercase it is stored in Excel. This happens about 10% of the times. And only with one of the ExcelRangeRead functions below, Global \$RTERuleName = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'I' & \$Row)
Func ExtractDCWData() Global \$PoolName = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'G' & \$Row) Global \$PoolDescription = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'H' & \$Row) Global \$RTERuleName = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'I' & \$Row) Global \$FirstName = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'F' & \$Row) Global \$LastName = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'E' & \$Row) Global \$Notes = _Excel_RangeRead(\$oWorkbook, 'CHFT Pools & RTE Rules', 'L' & \$Row) Sleep(200) EndFunc ;==>ExtractDCWData The excel column looks like this.

The script that writes the data out is as follows.
Func AddRTERule() MouseClick('Primary', 69, 657, 1) ;Click Rules... Sleep(200) MouseClick('Primary', 363, 228, 1) ;Click Type Sleep(200) MouseClick('Primary', 363, 266, 1) ;Click RTE Sleep(200) MouseClick('Primary', 363, 545, 1) ;Click New Rule Sleep(200) Send(\$RTERuleName) ;Enter Mnemonic Sleep(200) Send('{TAB}') ;Enter Description Sleep(100) ;Theres more lines of code in this function... EndFunc ;==>AddRTERule Any ideas?

• By Mungo
After an update installation to Win 10 V.1607 (64bit) I have noticed that help does not show formatted properly anymore e.g. with Images missing, tables, headers, sample code mal formatted etc.

However, if AutoIt3Help.exe is run as Administrator everything works fine.

I have already uninstalled AutoIt and SciTE for AutoIt and reinstalled both in the latest version.  I have used default locations for the installation under:

C:\Program Files (x86)\AutoIt3\...
Any idea?

Thanks

• By Leo1906
Hello there
I recently wanted to know how to differentiate between a mouse click and a touch click on controls in your GUI.
This can be interesting when using picture controls as buttons in combination with this UDF here.
No one could help me, so I tried my best to get it to work. And it works now! Unfortunately only for Windows 8 and above, as I had to use functions which are unavailable for older OS.
Additionally this was my first time writing DLLCalls myself. I hope (and think) that there are no mayor mistakes in it,

So here's the sample code: