How to loop thru x-y coordinates to find grid location?

View previous topic View next topic Go down

How to loop thru x-y coordinates to find grid location?

Post  Smulch on Mon Oct 26, 2009 1:35 pm

Hey folks, I'm a rusty VB programmer trying to use Autoit to automate a web control embedded in a VB app.

Scenario: I have a grid of links in the web control of known width and height pixel offsets. I need to automate clicking on an unknown number of those links at an unknown starting column location sequentially. I plan on using an input box for the user to input how many links need to be clicked. Then using a msgbox telling the user to position the mouse over the first column to start at, and calling MouseGetPos().

What I'm really up against here is my own internal(brain) logic errors and rusty coding practices keeping me from seeing how to go about this.

The grid is always 10 columns wide. The coordinates of column 1 is known and the offset between columns and rows is known. The column offset is 57px and row offset is 70px. I need to determine which column is the starting column based on the known location of column 1 and the difference of MouseGetPos(). Then click sequentially on the links in the remaining columns until the link in column 10 is clicked. Then move down a row and back to column 1 to continue clinking until the total number of links requested by the user have been clicked on. I.E. 34 links need to be clicked and the starting column is 171px away from column one.

The code to position the mouse and clicking or waiting for active windows isn't in question. I just cannot picture the loop structure given the unknowns of how many links and what the starting column to click is. I've been beating my head against the wall for a couple days now, and it is really starting to hurt, lol. I know I'm going to feel the fool when I see the code, but I'm at my whits end and figured it's time to ask before I start looking for a really tall building to leap from.

Thanks for any help you can give.
Smulch


Last edited by Smulch on Mon Oct 26, 2009 1:39 pm; edited 1 time in total (Reason for editing : clarification of first link location to click)

Smulch

Posts: 2
Join date: 2009-10-26
Location: South Carolina

View user profile

Back to top Go down

Re: How to loop thru x-y coordinates to find grid location?

Post  P5ych0Gigabyte on Mon Oct 26, 2009 2:01 pm

Hopefully the following can get you started in the right direction. You can see the loop structure in the grid function.


Code:
$GUI=GuiCreate("Grid",250,100)
GuiSetState(@SW_SHOW)

Grid(10,2,0,0,50,50)


While 1
   Sleep(100)
WEnd

Func Grid($Items,$ItemsPerX,$StartX,$StartY,$XSpacing,$YSpacing)
   For $X=0 to Round($Items/$ItemsPerX)-1
      For $Y=0 to $ItemsPerX -1
         GuiCtrlCreateButton("",$X*$XSpacing,$Y*$XSpacing,30,30)
      Next
   Next
EndFunc


Last edited by P5ych0Gigabyte on Mon Oct 26, 2009 2:04 pm; edited 1 time in total (Reason for editing : grammar)

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

Re:How to loop thru x-y coordinates to find grid location?

Post  Smulch on Tue Oct 27, 2009 1:41 pm

Thanks for the reply P5ych0Gigabyte.

Here's what I ended up working out (in case it might help someone else in the future).
There's a tad more code here than I really need to display, but I always thought it better to give too much info than not enough. Unfortunately a simple nested loop wouldn't suffice due to not knowing the starting column or the total number of links that would need to be accessed.

Code:
dim $xOffset = 57, $yOffset = 70, $iFrstCol = 260
dim $iBlingCount, $xyStartPos, $iBlingLocat, $xPos, $yPos

;   Ask how many bling to delete and where first one is located, what column.
   $iBlingCount = InputBox("Remove Bling","How many bling do you want to remove from  the manager?","0")

   MsgBox(8208,"Mouse position varifier","Make sure the mouse pointer" & @CRLF _
               & "is located directly over the" & @CRLF _
               & "'Remove' Link location of the" & @CRLF _
               & "first bling to remove, then press ENTER" & @CRLF _
               & "on your keyboard.")
   ;Wait until the Msgbox is gone.
   WinWaitNotActive("Mouse position varifier","Make sure the mouse")
   _WaitForWindow("Bling Manager - Mozzilla Firefox", 1, "")
   
;   Get the current mouse position.
   $xyStartPos = MouseGetPos()
   Sleep(100)

;   Determine Start position of the X and Y Coordinates
   $xPos=$xyStartPos[0]
   $yPos=$xyStartPos[1]

;   Determine what Bling we are starting at
   $iBlingLocat = Round(($xPos - $iFrstCol) / $xOffset)

   For $x=1 to $iBlingCount
      MouseMove($iFrstCol + ($xOffset * $iBlingLocat), $yPos)
                Sleep(50)
      MouseClick("Left")
      If $iBlingLocat = 10 Then
         $yPos = $yPos + $yOffset
         $iBlingLocat = 0
      EndIf
      $iBlingLocat = $iBlingLocat +1
   Next


Oh, I did have one more question about your code PSych0...
Besides being a sleep(delay) loop, what is the purpose of the "While 1" loop instead of just using the sleep stand-alone? And what changes the "1" to stop the loop?

Thanks,
Smulch

P5ych0Gigabyte wrote:Hopefully the following can get you started in the right direction. You can see the loop structure in the grid function.


Code:
$GUI=GuiCreate("Grid",250,100)
GuiSetState(@SW_SHOW)

Grid(10,2,0,0,50,50)


While 1
   Sleep(100)
WEnd

Func Grid($Items,$ItemsPerX,$StartX,$StartY,$XSpacing,$YSpacing)
   For $X=0 to Round($Items/$ItemsPerX)-1
      For $Y=0 to $ItemsPerX -1
         GuiCtrlCreateButton("",$X*$XSpacing,$Y*$XSpacing,30,30)
      Next
   Next
EndFunc

Smulch

Posts: 2
Join date: 2009-10-26
Location: South Carolina

View user profile

Back to top Go down

Re: How to loop thru x-y coordinates to find grid location?

Post  P5ych0Gigabyte on Tue Oct 27, 2009 8:04 pm

I added the loop so that it would not exit right away and allow you to see the grid. The loop would of exiting when the script was closed from the tray. If you dont know the amount of links maybe its possible to use IE.au3 to get your task done.

P5ych0Gigabyte
Admin

Posts: 27
Join date: 2009-10-21
Location: New Jersey,USA

View user profile http://www.c4free.info

Back to top Go down

View previous topic View next topic Back to top


Permissions of this forum:
You cannot reply to topics in this forum