Jump to content

Loop through pixelsearch until found


Recommended Posts

Hi,

I'm trying to use pixel search to see if a specific block corresponds with the pixel that is given on a window.

I got the searching part right, but my problem is that i need to search about 10 - 100 blocks on a window, and having to type out each pixel coords and color for each block would take quite sometime...

For example, all the block sizes are 123x543, the coords are ("85;510") [coords will differ] and color is (0xFFFFFFF)

Now what i need to do is, search in the specifc block;

PixelSearch( 85, 580, 123, 543, 0xFFFFFF )

to see if the color matches (0xFFFFFFF), if it doesn't, it needs to go onto the next block.

I've already check to see if they are all the same size apart from each other, and they are. 

So it would be like this:

PixelSearch( 85, 510, 123, 543, 0xFFFFFF ) ; the difference is 70 pixels

PixelSearch( 85, 580, 123, 543, 0xFFFFFF )

PixelSearch( 85, 650, 123, 543, 0xFFFFFF )

PixelSearch( 85, 730, 123, 543, 0xFFFFFF )

PixelSearch( 85, 800, 123, 543, 0xFFFFFF )

PixelSearch( 85, 870, 123, 543, 0xFFFFFF )

PixelSearch( 85, 940, 123, 543, 0xFFFFFF )

PixelSearch( 85,1010, 123, 543, 0xFFFFFF )

PixelSearch( 85, 1080, 123, 543, 0xFFFFFF )

PixelSearch( 85, 1150, 123, 543, 0xFFFFFF )

PixelSearch( 85, 1230, 123, 543, 0xFFFFFF )

PixelSearch( 85, 1300, 123, 543, 0xFFFFFF )

There are 11 blocks going horizontally. So if the first block doesn't match, it needs to go onto the next box.

 

This is what i have so far:

;call first variable and check
;==============================
WinWaitActive("AnimeHeaven.Eu - Watch anime online - Google Chrome")
    sleep("2000")
    MouseClick("left",139,49,1)
    Send($EpisodeCheck)
    Send("{Enter}")
    Sleep("3000")

;=================================================
Local $coord = PixelSearch( 85, 510, 123, 543, 0xFFFFFF )
If Not @error Then
    MouseMove(123,543,5)
    MouseClick("middle")
    ;
Else
    MsgBox($MB_OK, "Warning", "Does not match", 3)
EndIf

If you need the entire file, i'll gladly upload it.

 

Sorry for the horrible layout of this message.

Link to comment
Share on other sites

;call first variable and check
;==============================
WinWaitActive("AnimeHeaven.Eu - Watch anime online - Google Chrome")
    sleep(2000)
    MouseClick("left",139,49,1)
    Send($EpisodeCheck & "{ENTER}")
    Sleep(3000)

;=================================================
Do
   Local $coord = PixelSearch( 85, 510, 123, 543, 0xFFFFFF )
   If Not @error Then
      MouseClick("Middle", $coord[0], $coord[1])
   EndIf
Until IsArray($coord)

PixelSearch is a pretty poor way to automate browsers... Hopefully this code works for you but the colour you're searching for is white. Not sure if that's intended but a lot of websites have white as their background

Edited by badcoder123
Link to comment
Share on other sites

@badcoder123 Hi,

I am specifically looking for a white piece of text (since it will always be in that specific area), and i've narrowed the area to search for as well, so that it doesn't pick up a false true. 

As for your code, the part where you added;

$coord[0], $coord[1])

Will that be the first coords and then the second coords of the next block to check?

 

P.S: Thanks for tiding up my code a little xD

 

Link to comment
Share on other sites

1 hour ago, SouthLander said:

As for your code, the part where you added;


$coord[0], $coord[1])

Will that be the first coords and then the second coords of the next block to check?

 

Yes. In this case $coord[0] is the x coord and $coord[1] is the y coord. Once it detects the pixel in the area it will store an array (the [0] and [1]) in the variable and break out of the do loop. 

 

This might be more what you're looking for?

;call first variable and check
;==============================
WinWaitActive("AnimeHeaven.Eu - Watch anime online - Google Chrome")
   sleep(2000)
   MouseClick("left",139,49,1)
   Send($EpisodeCheck & "{ENTER}")
   Sleep(3000)

;=================================================
Local $y1[] = [510, 580, 650, 730, 800, 870, 940, 1010, 1080, 1150, 1230, 1300]
Do
   For $i In $y1
      Local $coord = PixelSearch( 85, $i, 123, 543, 0xFFFFFF )
      If Not @error Then
         MouseClick("Middle", $coord[0], $coord[1])
         ConsoleWrite("x " & $coord[0] & " y " & $coord[1] & @CRLF)
      EndIf
      ConsoleWrite($i & @CRLF)
   Next
Until IsArray($coord)

Keep in mind the position that you said in your post is that you want the y variable to change which ends at 1300. I've never seen a monitor with more than 1300 vertical pixels! Maybe you meant horizontal pixels?

Edited by badcoder123
Link to comment
Share on other sites

From your code you want to look at videos in a web browser. You would be MUCH better off using this:

https://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/

The reason is using pixel searching is a terrible way to automate. With the method I'm proposing you are hooking directly into controls thus if the window does not have focus, the script still works. With PixelSearch, when you lose focus, the script breaks. 

Link to comment
Share on other sites

@badcoder123 That is precisely what im looking for !

If the first block doesn't match the requirements it will be able to go to the next block and search until it is found. 

All i need to do now is to tweak it a bit and try it out. 

Thanks man!

22 hours ago, badcoder123 said:

This might be more what you're looking for?

;call first variable and check
;==============================
WinWaitActive("AnimeHeaven.Eu - Watch anime online - Google Chrome")
   sleep(2000)
   MouseClick("left",139,49,1)
   Send($EpisodeCheck & "{ENTER}")
   Sleep(3000)

;=================================================
Local $y1[] = [510, 580, 650, 730, 800, 870, 940, 1010, 1080, 1150, 1230, 1300]
Do
   For $i In $y1
      Local $coord = PixelSearch( 85, $i, 123, 543, 0xFFFFFF )
      If Not @error Then
         MouseClick("Middle", $coord[0], $coord[1])
         ConsoleWrite("x " & $coord[0] & " y " & $coord[1] & @CRLF)
      EndIf
      ConsoleWrite($i & @CRLF)
   Next
Until IsArray($coord)

 

And i did say that it was horizontal, lmao. I haven't seen a screen either that has 1300 vertical pixels xD

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...