Jump to content

PLEASE explain PixelSearch coordinates


Recommended Posts

I dont understand how does PixelSearch coordinates work.

I want to search area of the desktop 400x800 but no i dont understand how to use this coordinates.

 

PixelSearch (0,0,400,800,$Color) does not work.

I also tried to get window position for that so i had:

While 1
    $Pos = WinGetPos($Windowname)
    $Search = PixelSearch(Pos[0],Pos[1],Pos[02,Pos[3], $PixelColor, 0, 1, $WindowToSearch)
    If IsArray($Search) = True Then Exitloop
Wend

This is all done in a loop. Loop exist once color is found.

Nothing works and everything works i dont inderstan why its not just one or another.
I fiddle with coordinates but i cant pinpoint  what parameter effects what coordinate because it does not seem to work every time, complicating the issue.

Am i doing it right at least in theory ?

Link to comment
Share on other sites

  • Developers

Could you please STOP SHOUTING?

Which part of the helpfile explanation is difficult? 

Quote

PixelSearch

Searches a rectangle of pixels for the pixel color provided

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I understand all that.

What i dont understand is: STOP SHOUTING as well as: do i interpret it correctly when i read the help file or not.

Please look at what i am trying to accomplish and tell me if am doing it wrong or not.

 

PixelSearch (0,0,400,800,$Color) does not work for me.

It does not search 400x800 rectangular on the screen starting from top left corner of the screen. I know it because its not finding specified color in that area even if i allow shades of color (unless its extreme shade variance like 5-10).
So i would try to change one or a combination  of 4 coordinate parameters and i would get it to work but not as expected. I would end up searching the area that has absolutely nothing to do with what i entered.

Link to comment
Share on other sites

8 minutes ago, tonycst said:

It does not search 400x800 rectangular on the screen starting from top left corner of the screen.

Do you have more than one display screen?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Its like talking to a tech support in India :blink:

It does not search where i expect it to. If there was some sort of visual indication of the area it searches, i would be able to tell whats wrong, but it does not show me any visual representation of the search area its working on.

Edited by tonycst
Link to comment
Share on other sites

Can you post a working example of your script, and perhaps a screenshot of what it is you're looking for? Are you sure you're setting the coordinates correctly for the color you're looking for? I noticed in your OP the script is looking for the position of $Windowname, and you're using the handle for $Windowtosearch, are you sure they're the same window?

If you haven't already, use the Au3Info tool to get the exact color under the mouse cursor, check to make sure that the color matches what you are looking for, and it's where you think it should be.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Opt("WinTitleMatchMode", 2)
$WindowToSearch = "0.jpg"
$PixelColor = 0x6FDD00 ;lime green


While 1
    If WinExists ($WindowToSearch) = 1 Then
        $WinPos = WinGetPos ($WindowToSearch)
        $L = 0;$WinPos[0] ;from left
        $T = 0;$WinPos[1] ;from top
        $R = $WinPos[2] ;to right
        $B = $WinPos[3] ;to bottom
        $Search = PixelSearch($L,$T,$R,$B, $PixelColor, 2, 1,$WindowToSearch) ;2 for shade variation
        If IsArray($Search) = True Then
            ConsoleWrite (@CRLF & "Found it at X=" & $Search[0]& " Y=" & $Search[1] & " WinPos " & $L & " " & $T & " " & $R & " " & $B & " ")
        Else
            ConsoleWrite (@CRLF & "nothing at " & $L & " " & $T & " " & $R & " " & $B & " ")
        Endif
    Else
            ConsoleWrite (@CRLF & "Loking for window")
    EndIf
Wend

It searches desktop. not specified window.

Edited by tonycst
Link to comment
Share on other sites

  • Developers

Why are you providing a filename as last parameter which should represent a HWND?:

Quote

Parameters

left left coordinate of rectangle.
top top coordinate of rectangle.
right right coordinate of rectangle.
bottom bottom coordinate of rectangle.
color Color value of pixel to find (in decimal or hex).
shade-variation [optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the color. Default is 0 (exact match).
step [optional] Instead of searching each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1. It is not recommended to use a step value greater than 1.
hwnd [optional] Window handle to be used. Default is the desktop window.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I read the help file.

Because the window name i an testing it on is titled "0.jpg"

I want it to do the search inside a specific window, thats why i specified it.

It seems to search desktop instead.

I guess i could try to get the handle, instead of giving window name ?

Edited by tonycst
Link to comment
Share on other sites

This is the full script.

Opt("WinTitleMatchMode", 2)
$WindowToSearch = "0.jpg"
$PixelColor = 0x6FDD00 ;lime green


While 1
    If WinExists ($WindowToSearch) = 1 Then
        $WindowHandle = WinGetHandle ($WindowToSearch)
        $WinPos = WinGetPos ($WindowToSearch)
        $R = $WinPos[2] ;to right
        $B = $WinPos[3] ;to bottom
        $Search = PixelSearch(0,0,$R,$B, $PixelColor, 2, 1,$WindowHandle) ;2 for shade variation,1 for steps, and window name to search
        If IsArray($Search) = True Then
            ConsoleWrite (@CRLF & "Found it at X=" & $Search[0]& " Y=" & $Search[1] & " WinPos " & $R & " " & $B & " ")
        Else
            ConsoleWrite (@CRLF & "nothing found " & $WindowHandle)
        Endif
    Else
            ConsoleWrite (@CRLF & "Loking for window")
    EndIf
Wend

 

Edited by tonycst
Link to comment
Share on other sites

OK i was able to find my stupidity in getting the handle of the window.
I needed to move $WindowHandle = WinGetHandle ($WindowToSearch)  into the loop.
That resolved the problem with WindowHandle.

But that did not change the result. It still searching desktop only.

As soon as i move a icon on the desktop of that image i made into the search area, it picks it up.
As soon as i cover that spot on the DESKTOP where it finds the color (cover it with notepad editor for example) its not finding it.
Proving to me that it searches DESKTOP regardless of what Windowhandle says.
Unless windowhandle ALWAYS points to desktop ?


I tested to see if the window handle is changing (to confirm its not searching the same handle pointing to desktop) and its changing when i close and reopen the picture 0.jpg. so clearly handle is picked up correctly but it searches desktop.

Edited by tonycst
Link to comment
Share on other sites

  • Developers
4 hours ago, tonycst said:

 

I read the help file.

Because the window name i an testing it on is titled "0.jpg"

 

The windowname is NOT the same as a Window Handle! So keep on reading that helpfile how to get the window handle for the specified windowname!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

There is no evidence to prove this is for game automation Jos, it was an assumption since I'm privy in that topic.

You're just as guilty by confirming that what I said is true, and can be applied to game automation. Irregardless if it's for game automation, it can also be applied to other screen automation as well.

Link to comment
Share on other sites

  • Developers
22 minutes ago, 232showtime said:

you have two thread with same script. 188685-color-bot-key-press

nvm just got confused.

@232showtime please stop this posting of moderation type posts in threads. Either report a thread with a reason why or move on please.

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers
1 minute ago, FengHuangWuShen said:

There is no evidence to prove this is for game automation Jos

Where have I stated that? Guess you are confused with the other thread I just closed?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...