Jump to content
Sign in to follow this  
Dryden

Help Finding a window with PixelSearch

Recommended Posts

Dryden

Hello. This is my problem:

I'm doin a script that has to "see" a window in the screen and move it. I can't use any of the WinXX commands.

My Idea was searching for a color in the window and match the distance betwen it an another color, if the distance was the same that it would mean that thta was the window I wanted and moved it.

My problem is that there are other things in the screen with the same color ans as soon as the script finds the first one it stops searching for more, making it impossible to fin the window...

This is what I got:

$a=0
While $a==0
$coordenadas = PixelSearch(0,0,1024,768,0xFFCDC0,0,0)
    If PixelGetColor($coordenadas[0]+115,$coordenadas[1]+115) == 0xA7A6AA Then
    MouseClickDrag("left", $coordenadas[0]+20,$coordenadas[1],252,350)
    $a=1
    endif
WEnd

So the result is When it finds something of that "redish/pinkish" color it stops looking further, but If i move the window more to the left that the other stuff that has the same color, then the script does work in moving it...

Can someone help me please.

Thx in advance.

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
BillLuvsU

Why can't you use WinXX funcs?


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
Dryden

Why can't you use WinXX funcs?

cos' it isn't in windows. I is a graphic environment runing over windows.

So the easiest way... or so I thougt was to know 2 (or more) poins in the window and make the script look 4 them.

Wht I want to find the is color color 0xFFCDC0 if u add x+115 and y+115 to the coordinates where I found that color I should fin the color 0xA7A6AA If I find it is a true positive, else it should continue looking...


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
BillLuvsU

My only suggestion is to find a color unique to that window. I might be able to tell you more if you gave my information about this environment over windows.


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
Dryden

Heres an exemple that I drawed on Paint

Posted Image

I think is self explanatory.

The problem is that the window has no single color, every color in the window, are or will be in the background, so the best that I have is the distance between 2 colors. And that is unique for shure, cos there is no other screen section with that 2 colors with that distance between them...

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
PsaltyDS

It's just a loop problem: PixelSearch() returns the coordinates of the match found. Use them to restart the search from the remaining area. Each time you get a match on the first but not the second color, you will continue looking from the next pixel AFTER the previous match.

:(

P.S. If any part of the graphic is unique and consistent every time, you might use PixelChecksum() on that area to test for it.

:shocked:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Dryden

It's just a loop problem: PixelSearch() returns the coordinates of the match found. Use them to restart the search from the remaining area. Each time you get a match on the first but not the second color, you will continue looking from the next pixel AFTER the previous match.

:(

P.S. If any part of the graphic is unique and consistent every time, you might use PixelChecksum() on that area to test for it.

:shocked:

the problem with scaning the rest of the area with pixelsearch is that I cannot scan the whole area. here's an example:

Posted Image

With PixelSearch() the script will start searching from the top left to the bottom right so if I make the fists found the "zero" zone it wont scan Zone B or Zone C. Iv'e already tried tthis, by makeing something like:

$coordenadas = PixelSearch(0,0,1024,768,0xFFCDC0,0,0)

and in the second go:

$coordenadas = PixelSearch($cordenadas[0],cordenadas[1],1024,768,0xFFCDC0,0,0)

but the resul is:

it scans the zone A and when it finds a false positive it only scans the zone C. that means that if the true positive is in zone B or C it will never be found no matter how many time it repeats itself...

Please dudes... I'm a newb @ this language, I'm certain that theres a way to overcome this... Can somebody please help me find a solution?

Edited by Dryden

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
PsaltyDS

Don't scan the entire box. Scan one horizontal line of pixels at a time, and do it with a function that can call itself recursively to finish the current line if a "false positive" is found:

$Top = 0
$Left = 0
$Width = 1024
$Height = 768
$Color_1 = 0xFFCDC0
$Color_2 = 0xA7A6AA
$Found = False
For $y = $Top To ($Top + $Height - 115)
     $x = $Left
     $avPixel = _PixelSearchLine($x, $y, ($x + $Width - 115))
     If @error Then
          ContinueLoop
     Else
          $Found = True
          ExitLoop
     EndIf
Next

If $Found Then
     MsgBox(64, "Match", "Match found at: " & $avPixel[0] & "/" & $avPixel[1])
Else
     MsgBox(16, "No Match", "No match found.")
EndIf


Func _PixelSearchLine($iX, $iY, $iXLast)
     ; Start searching, one horizontal line, left to right
     Local $avFirstPixel = PixelSearch($iX, $iY, $iXLast, $iY, $Color_1)
     If @error Then Return SetError(1, 0, 0) ; No match return @error
     
     ; Match found to $Color_1, check $Color_2
     If PixelGetColor($avFirstPixel[0] + 115, $avFirstPixel[1] + 115) = $Color_2 Then
          ; Match found to $Color_2
          Return $avFirstPixel
     Else
          ; No match to $Color_2, search rest of this line
          $avFirstPixel[0] += 1
          If $avFirstPixel[0] <= $iXLast Then
               $avFirstPixel = _PixelSearchLine($avFirstPixel[0], $avFirstPixel[1], $iXLast)
               If @error Then
                    ; No match on the rest of the line
                    Return SetError(1, 0, 0)
               Else
                    ; Match found in remaing line
                    Return $avFirstPixel
               EndIf
           Else
                Return SetError(1, 0, 0)
           EndIf
     EndIf
EndFunc

I'm not on a Windoze box, so I can't test this... just doing it in my head, so don't be afraid to debug it a little.

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Dryden

Don't scan the entire box. Scan one horizontal line of pixels at a time, and do it with a function that can call itself recursively to finish the current line if a "false positive" is found:

$Top = 0
$Left = 0
$Width = 1024
$Height = 768
$Color_1 = 0xFFCDC0
$Color_2 = 0xA7A6AA
$Found = False
For $y = $Top To ($Top + $Height - 115)
     $x = $Left
     $avPixel = _PixelSearchLine($x, $y, ($x + $Width - 115))
     If @error Then
          ContinueLoop
     Else
          $Found = True
          ExitLoop
     EndIf
Next

If $Found Then
     MsgBox(64, "Match", "Match found at: " & $avPixel[0] & "/" & $avPixel[1])
Else
     MsgBox(16, "No Match", "No match found.")
EndIf
Func _PixelSearchLine($iX, $iY, $iXLast)
     ; Start searching, one horizontal line, left to right
     Local $avFirstPixel = PixelSearch($iX, $iY, $iXLast, $iY, $Color_1)
     If @error Then Return SetError(1, 0, 0) ; No match return @error
     
     ; Match found to $Color_1, check $Color_2
     If PixelGetColor($avFirstPixel[0] + 115, $avFirstPixel[1] + 115) = $Color_2 Then
          ; Match found to $Color_2
          Return $avFirstPixel
     Else
          ; No match to $Color_2, search rest of this line
          $avFirstPixel[0] += 1
          If $avFirstPixel[0] <= $iXLast Then
               $avFirstPixel = _PixelSearchLine($avFirstPixel[0], $avFirstPixel[1], $iXLast)
               If @error Then
                    ; No match on the rest of the line
                    Return SetError(1, 0, 0)
               Else
                    ; Match found in remaing line
                    Return $avFirstPixel
               EndIf
           Else
                Return SetError(1, 0, 0)
           EndIf
     EndIf
EndFunc

I'm not on a Windoze box, so I can't test this... just doing it in my head, so don't be afraid to debug it a little.

:shocked:

I think u r in the right track, but I dunno enought of autoit to correct your script. when I run it It says:

Line 7 (File "C:\blábláblá"):

$Found = False

$Found ^ Error

Error: Unknown function name.

then I tried replacing the True/False For 0/1 (it's the only way I know :S). And I got this error:

Line 29 (File "C:\blábláblá"):

If @error Then Return SetError(1, 0 ,0 );No match return @error

If @error Then Return ^Error

Error: Incorrect number of parameters in function call.

can u help me please? does it run in your pc?

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
PsaltyDS

I think u r in the right track, but I dunno enought of autoit to correct your script. when I run it It says:

then I tried replacing the True/False For 0/1 (it's the only way I know :S). And I got this error:

can u help me please? does it run in your pc?

Wow. What version of AutoIt are you running? :(

I'm still not on Windows (busy buring Ubuntu Fiesty Fawn CDs), so I can't test right now, but those particular lines look very routine...

True/False are standard AutoIt Keywords.

The use of Return SetError() is also pretty tame.

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Dryden

Wow. What version of AutoIt are you running? :shocked:

V3... :S

"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
Dryden

plzz help :shocked:


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
PsaltyDS

You've broken something... :shocked:

I tested my demo above on a windows box with AutoIT 3.2.2.0 Prod.

It does Tidy in SciTE with no errors, compiles with no errors, and works fine (with different colors for my desktop).

:(


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Dryden

I copied It as it is...

Scite errors:

C:\Documents and Settings\Dryden\Ambiente de trabalho\win.au3(29,44) : ERROR: SetError() [built-in] called with wrong number of args.

If @error Then Return SetError(1, 0, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Dryden\Ambiente de trabalho\win.au3(42,44) : ERROR: SetError() [built-in] called with wrong number of args.

Return SetError(1, 0, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Dryden\Ambiente de trabalho\win.au3(48,40) : ERROR: SetError() [built-in] called with wrong number of args.

Return SetError(1, 0, 0)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Dryden\Ambiente de trabalho\win.au3 - 3 error(s), 0 warning(s)

!>AU3Check ended.rc:2

>Exit code: 0 Time: 4.309


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

Share this post


Link to post
Share on other sites
PsaltyDS

I copied It as it is...

Scite errors:

Well, it should work, but since I am not using SetError() to change the @extended or Return value, just change each instance of SetError(1,0,0) to SetError(1) and see what it does.

Plus, when I asked before about your AutoIT version, you only gave part of the version number. What is the full version number of your AutoIT install?

MsgBox(64, "AutoIT", "Version: " & @AutoItVersion)

:shocked:

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Dryden

Problem solved... PsaltyDS U r a genious... It really works... The reason It wasn't workins was that I sill had the V3.1... :"> Updated to 3.2 and It's all fine now... :shocked:

Thx mate...


"Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life." - Terry Pratchett.

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
Sign in to follow this  

×