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

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I'm trying to create a webscrape script using AutoIt.  A non-profit I'm involved with is using GroupSpaces.com and there is no notification to the group when someone posts a new topic to the forum.  I'm including IE.au3

      #include <MsgBoxConstants.au3>
      #include <Array.au3>
      #include <String.au3>
      ; Open Groupspaces.com
      Global $oIE = _IECreate ("http://www.groupspaces.com")
      _IENavigate($oIE,"http://groupspaces.com/MyCrazyTest/forum/")
      ;Grab all the links on the Forum page
      Global $oLinksCategoryPage = _IELinkGetCollection($oIE)
      For $oLink In $oLinksCategoryPage
          Local $oLinkHRef = $oLink.href
          If StringInStr($oLinkHRef,"forum_id") Then
              ;This is a category. Click into it.
              _IENavigate($oIE,$oLinkHRef)
      Sleep(3)
              ;Back out to Category List
              _IEAction($oIE,"back")
          EndIf
      Next
      _IEQuit($oIE)
    • xgjengen
      By xgjengen
      Hey guys!
      Im new when it comes to scripting and i follow some videos on how to make clicks and such. So i will say i know the basics alrady.
      However, im having a really big problem
      When i run the script is works fine with the clicks and all. But if i run it one or two more times it just moves to very inaccurate positions. YES, i have tried mulitple times to change positions and such but no luck. My script is working its just so inaccurate that im unable to use it. Are there any solution for this?
      I have also set the camera to a specific position. I have also tried other camera angles, no luck there either. Making more smoother macro movements does not seem to work aswell.
      I have also tried to have clicks away from the minimap, since i know some youtuber had problem with inaccuracy because of this.
      I came here because i was googling and did not see anyone else having this problem, or mentioning it. So if someone have a solution, i would be happy!! All i have seen are people trying to change the resolution. But it has nothing to do with that. I heard someone mention controlmouseclick. However are there any differences? I have also A window selection in my script so it changes to the window the macro will be running in. Resolution is not changing or anything. I have also tried other macros and same problem there.
       
      Also does anyone know or can teach me how pixel search works? I want the macro to be able to click at the correct character instead of waiting for the character to get in the position its searching for.
    • gononono64
      By gononono64
      Hey there,
      I'm having some issues quick-sorting my 2d array imported from a database. Im trying to sort the array based on the name that would be returned in $array[$n][2]. The code i posted works for smaller arrays but for some reason when i try to sort my imported array (around 9000 indexes), I get "Recursion level has been exceeded". I understand that this is maybe due to lack of returns but i couldn't find an ideal spot to stick em and again it seems to work with smaller bits of code. Could it be that 9000 is too much?
      I would normally just trial and error it until i figured it out but due to the length of time to load and buffer my array it's become too time consuming. Really I'm just hoping there is a quick fix that someone with more experience happens to know.
      Thank you
       
      ;;---------------------------------------------This Works---------------------------------------------------- Local $a[7][2] = [ _ ["1", "asdfashks"], _ ["2", "SubStrlkghjing1"], _ ["3", "jdfghjsergh"], _ ["4", "nertynert"], _ ["5", "cvbncvjkrt"], _ ["6", "avbncvjkrt"], _ ["7", "oytuoyuop"]] Quicksort($a,1,0,6) _ArrayDisplay($a) ;;------------------------------------------This Does Not--------------------------------------------------------- Quicksort($aLargeData, 1, 0, Ubound($aLargeData) - 1) _ArrayDisplay($aLargeData) ;;----------------------------------------Quicksort Function------------------------------------------------------ Func Quicksort(ByRef $Array, $secondIndex, $First, $Last) Local $pivot, $i, $j, $temp If $First < $Last Then $pivot = $First $i = $First $j = $Last While ($i < $j) While (StringCompare($Array[$i][$secondIndex], $Array[$pivot][$secondIndex]) <= 0) And ($i < $Last) $i += 1 WEnd While (StringCompare($Array[$j][$secondIndex], $Array[$pivot][$secondIndex]) > 0) $j -= 1 WEnd If ($i < $j) Then _ArraySwap($Array, $i, $j) _ArraySwap($Array,$pivot,$j) Quicksort($Array, $secondIndex, $First,$j-1) Quicksort($Array, $secondIndex, $j+1,$Last) WEnd EndIf EndFunc  
    • RyukShini
      By RyukShini
      I was wondering if its possible to make anything like this in AutoIT

       
      function toArr(str) { var ret = Array((str.length + 3) >> 2); // String to array of 32 bit ints for (var i = 0; i < str.length; i += 4) { // FYI: // NaN << x === 0 // x | NaN === x ret[i >> 2] = (str.charCodeAt(i ) << 24) | (str.charCodeAt(i+1) << 16) | (str.charCodeAt(i+2) << 8) | str.charCodeAt(i+3); } return ret; } function megaKdf(pw) { var pwkey = [0x93c467e3, 0x7db0c7a4, 0xd1be3f81, 0x0152cb56]; var arrPw = toArr(pw); var aes = Array((arrPw + 3) >> 2); // Init aes keys for (var i = 0; i < arrPw.length; i += 4) { aes[i >> 2] = new sjcl.cipher.aes([arrPw[i]|0, arrPw[i+1]|0, arrPw[i+2]|0, arrPw[i+3]|0]); } // Generate password key for (var i = 0; i < 65536; i++) { for (var j = 0; j < aes.length; j++) { pwkey = aes[j].encrypt(pwkey); } } return pwkey; } function loginHash(pwKey, email) { var aes = new sjcl.cipher.aes(pwKey); var arrEmail = toArr(email); var hash = [0, 0, 0, 0]; // Compress email with xor for (var i = 0; i < arrEmail.length; i++) { hash[i & 3] ^= arrEmail[i]; } // Generate hash for (var i = 0; i < 16384; i++) { hash = aes.encrypt(hash); } return sjcl.codec.base64.fromBits([hash[0], hash[2]], true, true); } function badRand32() { return Math.floor(0x100000000 * Math.random()); } function generateMasterKey() { return [badRand32(), badRand32(), badRand32(), badRand32()]; } function confirmationLinkHash(pwKey) { var aes = new sjcl.cipher.aes(pwKey); return aes.encrypt([badRand32(), 0, 0, badRand32()]); } function updateHashes(email, pw) { var pwKey = megaKdf(pw); var masterKey = generateMasterKey(); var clHash = confirmationLinkHash(pwKey, masterKey); var lHash = loginHash(pwKey, email); var aes = new sjcl.cipher.aes(pwKey); return lHash; } function htmlentities(str) { return str.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;"); } function analyzeLink(link, pw) { var linkHex = "N/A"; var masterKey = "N/A"; var encMasterKey = "N/A"; var pwHash = "N/A"; var unknown = "N/A"; var email = "N/A"; var spacer = "N/A"; var name = "N/A"; var unknown2 = "N/A"; if (link.substr(0, 27) == "https://mega.co.nz/#confirm") { link = link.substr(27); } if (link.substr(0, 19) == "mega.co.nz/#confirm") { link = link.substr(19); } if (link.substr(0, 8) == "#confirm") { link = link.substr(8); } if (link.search(/^[0-9A-Za-z\-_]*$/) == 0) { link = sjcl.codec.hex.fromBits(sjcl.codec.base64.toBits(link, true)); var pos; for (pos = 94; pos < link.length; pos += 2) { if (link.substr(pos, 2) == "09") { break; } } if (pos < link.length) { var pwKey = megaKdf(pw); var aes = new sjcl.cipher.aes(pwKey); var linkHash = aes.decrypt(sjcl.codec.hex.toBits(link.substr(32, 32))); if (linkHash[1] == 0 && linkHash[2] == 0) { masterKey = (new sjcl.cipher.aes(pwKey)).decrypt(sjcl.codec.hex.toBits(link.substr(0, 32))); masterKey = 'Base64: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.base64.fromBits(masterKey, true, true) + '</span> (hex: <span style="color:#f00; font-family:monospace;">' + sjcl.codec.hex.fromBits(masterKey) + '</span>)'; } else if (pw != "") { masterKey = "Wrong password"; } encMasterKey = '<span style="color:#f00; font-family:monospace;">' + link.substr( 0, 32) + '</span>'; pwHash = '<span style="color:#080; font-family:monospace;">' + link.substr(32, 32) + '</span>'; unknown = '<span style="color:#00f; font-family:monospace;">' + link.substr(64, 30) + '</span>'; email = link.substr(94, pos - 94); spacer = '<span style="color:#0cc; font-family:monospace;">09</span>'; name = link.substr(pos + 2, link.length - 16 - pos - 2); unknown2 = '<span style="color:#000; font-family:monospace;">' + link.substr(link.length - 16) + '</span>'; linkHex = '<span style="font-family:monospace;">' + encMasterKey + " " + pwHash + " " + unknown + ' <span style="color:#888; font-family:monospace;">' + email + '</span> ' + spacer + ' <span style="color:#f0f; font-family:monospace;">' + name + '</span> ' + unknown2 + '</span>'; email = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(email))) + ' (<span style="color:#888; font-family:monospace;">' + email + '</span>)'; name = htmlentities(sjcl.codec.utf8String.fromBits(sjcl.codec.hex.toBits(name))) + ' (<span style="color:#f0f; font-family:monospace;">' + name + '</span>)'; } } ge("linkHex").innerHTML = linkHex; ge("linkMasterKey").innerHTML = masterKey; ge("linkEncMasterKey").innerHTML = encMasterKey; ge("linkPwHash").innerHTML = pwHash; ge("linkUnknown").innerHTML = unknown; ge("linkEmail").innerHTML = email; ge("linkSpacer").innerHTML = spacer; ge("linkName").innerHTML = name; ge("linkUnknown2").innerHTML = unknown2; }  
    • knuxfighter
      By knuxfighter
      Hello. I've been working with Imagesearch library lately and it did a good work, although I moved to a new PC and didn't copy the old files with me so I downloaded the Imagesearch from the following post
       hoping that it will work. It doesn't though. First time I when I use (run as subscript to my code) the Imagesearch.au3, Scite finds errors (missing spaces). Ctrl+T (scite tidy) fixes these missing spaces but the script returns the following error on every run after:
      _ImageSearch('search.bmp', 0, $x, $y, 0) outputs
       
      "C:\Users\Knuckles\Desktop\AutoIt\include\ImageSearch.au3" (44) : ==> Subscript used on non-accessible variable.: If $result[0] = "0" Then Return 0 If $result^ ERROR no matter if I put the searched bmp in the script folder or folder img in the script directory. Also, it doesn't matter if the searched image on screen or not, it returns the same.

      Can you provide me any help please? I remember having these problems 2 years ago when I first met the imagesearch library also (I fixed it somehow though in that time). Seems nothing changed.

      Using this version posted in the following post gives the same error:
      Also I run windows 10 64bit and I have no shell options for script editing, running as x86 or whatever as I used to have on windows xp/7. I went through some steps like deleting a key in registry and I even reinstalled autoit and scite but that only resulted to au3 as unrecognized file format and not in getting back the menus and the icon on au3 files. Any thoughts on this?

      Edit: Installing 64-bit AutoIt and using 64bit ImageSearch is no change.
      code.au3

      FOUND WORKING: http://www.codebot.de/index.php/Thread/12713-Imagesearch-au3-funktioniert-nicht/
       but why is this one working and the original aren't? :(