K3STROS

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 this post


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


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


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


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


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

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

    • DagSa
      By DagSa
      Try to find a solution for help files to my autoit executable.
      Its installed from simple XP-POS cash computers to desktop with windows 7, 8, 10.
      The compiled AutoIt program itself work everywhere, but the help file??
      I need a help file called from from the program and I don't really know what working best in all OS platforms.
      1. A wordfile is helpful enough, but word is not installed everywhere.
      2. RTF is very big files with pictures.
      3. I could save it as pdf, but not all have it either.
      4. Tried  .MHT file, but downside is browser could cover hole screen if browser closed this way. I have not found any way to resize it to specific size when open up.
      5. Use of IE.au3 lib. Well it could open mht files ,but always got question about use it as default browser or not. Think this also make IE browser lose control so I could not resize.
      6. Look at making a  .CHM file, but I don't think its the future do use that format. (.hlp is no no and old)

      Any tips of do it in autoit or make a call to open up in some nice format working everywhere.
       
    • au3leecher
      By au3leecher
      Hellow everybody,
      I tryed to manipulate a game called "Assault Cube" which is a easy beginning in coding. I run the code but the wished value doesn't change, i don't understand why.
      The Pointers are fine, I checked that the pointers don't change every time while restart the game.
      My Code:
      <snip>
      _____________________________________________________________________________________________________________________________________________________________________________________________
      Checklist:
      The Offsets are 18C & 4
      In Cheat Engine: ("ac_client.exe"+0010F418) <- Pointer
      4 Bytes = 'dword'
       
    • geekyworld
      By geekyworld
      Hi. I want to read the help file on my Kindle ebook reader (to protect my eyes). Is it available in Kindle or epub format? I tried converting it myself but the results were not very good.
      --Thanks!
    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?