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

    • JustinZandee
      By JustinZandee
      I need a random string generator which creates 15 letters/numbers.
      How can I make that?
    • SkysLastChance
      By SkysLastChance
      I get this error, Whenever I try to find a date. Does anyone have any idea why? I saw some post from 2015, However I would imagine this is fixed by now. @water
      >"J:\Temporary Files\XXXXXXXXX\AutoIt\AutoIt\AutoIt\SciTe\..\autoit3.exe" /ErrorStdOut "C:\Users\XXXXXX\Desktop\Call Report Automation.au3"     "J:\Temporary Files\XXXXXXXX\AutoIt\AutoIt\AutoIt\Include\Excel.au3" (656) : ==> The requested action with this object has failed.: $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][1] = $oMatch^ ERROR >Exit code: 1    Time: 5.791 #include <Excel.au3> Global $sExcelFile1 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsm)") Global $sExcelFile2 = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "Excel Sheet (*.xlsx;*.xls)|All (*.*)") If FileExists($sExcelFile2) Then Global $oExcel2 = _Excel_Open () $oExcel2 = _Excel_BookOpen($oExcel2,$sExcelFile2) EndIF If FileExists($sExcelFile1) Then Global $oExcel1 = _Excel_Open () $oExcel1 = _Excel_BookOpen($oExcel1,$sExcelFile1,Default,Default,"2007") EndIF $oRead = _Excel_RangeRead ($oExcel2,Default,"A2",3) _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7") Sleep (1000) _Excel_RangeFind ($oExcel1,$oRead,"E4:FD92") MsgBox (0,"Test",$oRead) UPDATE:
      If I take out this line it works. By works I mean I don't get the error. :/  However, I need it. I am just confused.
      _Excel_RangeWrite ($oExcel1,"Calls Handled",$oRead,"BY7")  
      UPDATE 2: I also get this error when trying to use the helpfile examples. I have version 3.3.14.2
      \AutoIt\AutoIt\AutoIt\Include\Excel.au3" (670) : ==> The requested action with this object has failed.: $oSheet = $oWorkbook.Sheets($iIndexSheets) $oSheet = $oWorkbook^ ERROR >Exit code: 1 Time: 0.8931  
    • StudioMaker
      By StudioMaker
      Hey anyone knows how i can have a inputbox that is connected to an HotKeySet? Like if u put in like "a" in the inputbox it sets the hotkey to "a"?
       
    • Ubermensch
      By Ubermensch
      Hello,
      I am currently trying to automatically click the "Yes" button in the ActiveX prompt/popup message after opening the IE (html).
      At 1st, I encounter the "Allow Blocked Content". I already resolve it just by changing settings in the IE Options. But after resolving the "Allow Blocked Content", there's a popup message appear.
      I have attached the ActiveX Prompt.
      Here is the 1st code that I try to use.
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) AdlibRegister("_ActiveXRun",250) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) Func _ActiveXRun() $retWin = WinGetHandle("[Class:Button]","") $winTitle = "[HANDLE:" & $retWin &"]" $ctrlHandle = ControlGetHandle($winTitle,"", "[CLASS:Button; INSTANCE:2]") $ctrlTitle = "HANDLE:" & $ctrlHandle &"]" WinWaitActive($ctrlTitle,"[CLASS:Button; INSTANCE:2]",10) $k = ControlGetPos($winTitle, "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] WinActivate ($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?") ControlFocus($winTitle,"An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?","[CLASS:Button; INSTANCE:2]") ControlClick($winTitle, "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) ControlSend($winTitle, "", "[CLASS:Button; INSTANCE:2]", "{ENTER}", 0) EndFunc Here is the console output.
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" /UserParams +>12:44:11 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\april\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\april\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3 +>12:44:11 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\AWD10.1.au3" (31) : ==> Subscript used on non-accessible variable.: $x = $k[0] $x = $k^ ERROR ->12:44:24 AutoIt3.exe ended.rc:1 +>12:44:24 AutoIt3Wrapper Finished. >Exit code: 1 Time: 13.76 I also tried a simpler code.
      include <IE.au3> #include <MsgBoxConstants.au3> #include <WinAPI.au3> _IECreate("C:\Users\april\Documents\Logo\JRB\AutoIt\AutoBOT\AWD10\sampleAWD10.html",0,1,0) Local $oIE = _IEAttach("", "instance", 1) _IELoadWait($oIE) $k = ControlGetPos("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]") $x = $k[0] $y = $k[1] ControlClick("[CLASS:#32770]", "","[CLASS:Button; INSTANCE:2]","primary",1,$x,$y) Local $oLastName = _IEGetObjByName($oIE, "Text4") Local $oGetItem = _IEGetObjByName($oIE, "getitem") _IEAction($oGetItem, "click") MsgBox($MB_SYSTEMMODAL, "Form Element Value", _IEFormElementGetValue($oGetItem)) There's no error in the console output for the 2nd code I have tried.
      And here is the Window Info for the ActiveX prompt.
      >>>> Window <<<< Title: Internet Explorer Class: #32770 Position: 580, 338 Size: 376, 146 Style: 0x94C808C4 ExStyle: 0x00010101 Handle: 0x00000000001516FA >>>> Control <<<< Class: Button Instance: 2 ClassnameNN: Button2 Name: Advanced (Class): [CLASS:Button; INSTANCE:2] ID: 1 Text: &Yes Position: 184, 77 Size: 80, 22 ControlClick Coords: 37, 12 Style: 0x50010000 ExStyle: 0x00000004 Handle: 0x00000000001215DE >>>> Mouse <<<< Position: 228, 120 Cursor ID: 0 Color: 0xFFFFFF >>>> StatusBar <<<< >>>> ToolsBar <<<< >>>> Visible Text <<<< &No An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction? &Yes >>>> Hidden Text <<<<  

    • lacamel
      By lacamel
      Hi there,
      I did a short script to simulate mouse click when pixel change is detected on a small section of the screen. I recorded the screen many times to see the accuracy of the script and it seems though response time varies widely.
      Here's the script 
      $checksum = pixelchecksum (400,250, 402,252)
      While $checksum = pixelchecksum (400,250, 402,252)
      Sleep (50)
      Wend
      Sleep (300)
      Mouseclick("left", 450,300, 1, 0)
      Counting from the pixel change to the mouse click, i get response times anywhere between 370ms and 550ms. I've tried running au3 and exe, changed sleep times but never gotten an accurate response time based on the script. Any ideas why?