# Is this done correctly?

## Recommended Posts

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

• #### Error when run as a admin, Error on a line of code that does not exist (Error: Variable must be of type "Object") - (Moved)

By Garcia,

• 4 replies
• 495 views
• #### Can't connect to MySQL server - (Moved) 1 2 3

By 20Ice18,

• 41 replies
• 2,688 views
• #### Strange ERROR box

By pete_wilde,

• 7 replies
• 843 views
• #### Script crashing on opening win 11 start menu

By raj9039852537,

• 2 replies
• 948 views
• #### Script that uses a lot of mouse click coordinates

By TheAutomator,

• 9 replies
• 2,481 views
×

• Wiki

• Back

• #### Beta

• Git
• FAQ
×
• Create New...