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

    • nikink
      By nikink
      Hi all,
      I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14.
      I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong.
      Anyway, the code to replicate my issue is:
      Test('username', 'DOMAIN') ; THIS ERRORS: ;Test('localun', 'DOMAIN') ; THIS ERRORS: ;Test(' ', ' ') ; THIS ERRORS: ;Test('', '') ; THIS ERRORS: ;Test('localun', '') ; THIS ERRORS: ;Test('', 'DOMAIN') Func Test($un, $dom) $compName = 'PCNAME' $FullName = '.' $Description = '.' ; get the WIM object $objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2") ; get default user full name and description $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") If IsObj($objAccount) Then $FullName = $objAccount.FullName $Description = $objAccount.Description EndIf ConsoleWrite($FullName & @CRLF) ConsoleWrite($Description & @CRLF) Return EndFunc  
      On my old PC this code will output just . and . for each of those line currently commented out. Which is fine.
      On my new PC any of those commented out lines of code cause an error, and the script won't even compile.
      $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") $objAccount = $objWMIService^ ERROR I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement.
      Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?
    • kcvinu
      By kcvinu
      Hi all,
      How can i get notified when user clicks on a combo box's edit area ? This is my code so far. 
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <ComboConstants.au3> #include <ListBoxConstants.au3> Global $btn ; creates a window Global $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) GUICtrlSetFont(-1,12,400) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetFont(-1,12,400) GUIRegisterMsg($WM_COMMAND, "MyEventCallback") GUIRegisterMsg($WM_SIZE, "MyEventCallback") GUIRegisterMsg($WM_NOTIFY, "NotifyManager") GUISetState(@SW_SHOW) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") Do $Event = GUIGetMsg( ) Until $Event = $GUI_EVENT_CLOSE Func MyEventCallback($hwnd, $message, $wParam, $lParam) Select Case $message = $WM_COMMAND ;---------------------------------------------------------------- If LoWord($wParam) = $cmb Then ; if control id is combox's Then Local $Notification = HiWord($wParam) Select Case $Notification = $CBN_DROPDOWN ; here we check the notification code. ConsoleWrite("$CBN_DROPDOWN Worked " & @MIN & ":" & @SEC & @CRLF) Case $Notification = $CBN_EDITCHANGE ; here we check the notification code. ConsoleWrite("$CBN_EDITCHANGE Worked " & @MIN & ":" & @SEC & @CRLF) ; **** Here i want add the code for combo box clicking. EndSelect ;--------------------------------------------------------------------- ElseIf LoWord($wParam) = $lstbx Then Local $Notification = HiWord($wParam) Select Case $Notification = $LBN_SELCHANGE ConsoleWrite("$LBN_SELCHANGE" & @CRLF) EndSelect EndIf ;------------------------------------------------------------------ Case $message = $WM_SIZE EndSelect Return $GUI_RUNDEFMSG EndFunc ;==>ProGUI_EventCallback Func NotifyManager($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If DllStructGetData($tagNMHDR, 3) = $NM_LDOWN Then ConsoleWrite("Notify Worked" & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc Func LoWord($Variable) Return BitAND($Variable, 0xFFFF) EndFunc Func HiWord($Variable) Return BitShift($Variable, 16) EndFunc  
    • ags911
      By ags911
      I have a script that has to work on multiple resolutions but each resolution has slightly different co-ordinates due to automatic UI scaling. I have had to make separate files for each but would like to implement them all in one script. I have a similar program written for Java which uses else if statements to use different co-ordinates for each resolution after it has been detected. I'm not good with Java so I would like to implement this on AutoIt before later making a Java version.
       
      This is a snippet of the autoit code I have.
      ToolTip("1 - Search")
      MouseClick("Left", @DesktopWidth *0.823, @DesktopHeight *0.925, 1, 25)
      ToolTip("2 - Buy Now")
      MouseClick("Left", @DesktopWidth *0.83, @DesktopHeight *0.798, 1, 27)
      ToolTip("3 - OK")
      MouseClick("Left", @DesktopWidth *0.555, @DesktopHeight *0.596, 1, 15)
      ToolTip("4 - OK Clear Error")
      MouseClick("Left", @DesktopWidth *0.49, @DesktopHeight *0.597, 1, 30)
      ToolTip("5 - Back to Search")
      MouseClick("Left", @DesktopWidth *0.161, @DesktopHeight *0.108, 1, 15)
       
      This is a snippet of a java code I used.
      Thanks.
      private static void goToSearch(double maxX, double maxY, Robot bot) throws InterruptedException {     int currentX = 0;     int currentY = 0;     if (maxX == 2650 && maxY == 1440) {         currentX = 734;         currentY = 1316;     } else if (maxX == 1920 && maxY == 1200) {         currentX = 551;         currentY = 1096;     } else if (maxX == 1920 && maxY == 1080) {         currentX = 551;         currentY = 1042;     } else if (maxX == 1680 && maxY == 1050) {         currentX = 482;         currentY = 959;     } else if (maxX == 1440 && maxY == 900) {         currentX = 413;         currentY = 822;     } else if (maxX == 1366 && maxY == 768) {         currentX = 392;         currentY = 741;     } else if (maxX == 1280 && maxY == 800) {         currentX = 367;         currentY = 731;
    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?