Sign in to follow this  
Followers 0
IamMike4Life

Having trouble understanding PixelSearch

10 posts in this topic

Hi all, I'm new to auto it but not to programming. My skill is with C# but decided to give Autoit a try.

I seem to be having trouble with understanding the way "PixelSearch" works. Lets say I have a screen resolution of say (1680x1050) and want to scan for a given pixel within a rectangle smaller then this resolution, Example:

Posted Image

How would I go about doing this? Heres the code im using which doesnt seem to do the trick:

$Coord= PixelSearch(500, 500, @DesktopWidth - 500, @DesktopHeight - 500, 0xB08978, 3)

Sleep(100)
If Not (@error) Then
    If (IsArray($Coord)) Then
        MouseMove($Coord[0], $Coord[1])
    EndIf
EndIf

I'm guessing that I dont fully understand the coords and its the reason why it's not working how I would like it to work. If you know the answer and don't mind spending the time to help me, that would be great. Thanks

Share this post


Link to post
Share on other sites



you dont need ()'s around you arguments in the if statments. also, you r doing 2 error checks. the If Not @error and IsArray($Coord) will do the same thing. i would just use one or the other. and tipically, i would use IsArray

secondly, if you r gonna do BOTH the @error and IsArray, i would put an else statment on the @error. like so:

$Coord= PixelSearch(500, 500, @DesktopWidth - 500, @DesktopHeight - 500, 0xB08978, 3)

Sleep(100)
If Not (@error) Then
    If (IsArray($Coord)) Then
        MouseMove($Coord[0], $Coord[1])
    EndIf
Else
    MsgBox(0, "Error", "Pixel was not found.")
EndIf

this will let you kno if the pixel was skipped because you have a step of 3. you might wanna try doing the default step which is 1

Share this post


Link to post
Share on other sites

you dont need ()'s around you arguments in the if statments. also, you r doing 2 error checks. the If Not @error and IsArray($Coord) will do the same thing. i would just use one or the other. and tipically, i would use IsArray

secondly, if you r gonna do BOTH the @error and IsArray, i would put an else statment on the @error. like so:

$Coord= PixelSearch(500, 500, @DesktopWidth - 500, @DesktopHeight - 500, 0xB08978, 3)

Sleep(100)
If Not (@error) Then
    If (IsArray($Coord)) Then
        MouseMove($Coord[0], $Coord[1])
    EndIf
Else
    MsgBox(0, "Error", "Pixel was not found.")
EndIf

this will let you kno if the pixel was skipped because you have a step of 3. you might wanna try doing the default step which is 1

Yea, I realized that I didn't need the brackets around the code. It's just a coding habit from using C# and cant seem to break it ;)

As for the 2 error checks, I guess that would be a good idea to use just one. But as for my OP, I take it you wouldn't be able to help me with my problem?

Share this post


Link to post
Share on other sites

well u have it set up correctly. so what exactly DOESNT it do? does it not find the pixel? or does it find a different pixel?? because that is how pixel search works. it starts from the top left corner of the defined area you want to search and works its way to the right of the first line than moves to the next line if no pixel is a match. it will return the coordinates of the FIRST positive result. the step feature is how many pixels it skips. so if the step is 1 it searches EVERY pixel. a step of 2 will search every OTHER pixel and so one.

if you r looking for (just an example) 1 red pixel in an entirely black screen with only 1 pixel that is red, if you use a step of 2, you have a 50% chance of missing that pixel.

if this still doesnt answer your question, then im obviously missing the question or i dont have enough info to give you an answer

Share this post


Link to post
Share on other sites

the step feature is how many pixels it skips. so if the step is 1 it searches EVERY pixel. a step of 2 will search every OTHER pixel and so one.

The 3 in his example is not the step size, it's the shade variation from the color being looked for.

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

Share this post


Link to post
Share on other sites

The 3 in his example is not the step size, it's the shade variation from the color being looked for.

oh god....you're right. thats embarrasing ;)

Share this post


Link to post
Share on other sites

Sorry, I thought my question said it all but after re-reading, I guess I missed a few things. First of all, it does work, but it doesn't. The white area in my OP is the area I want to search, but it goes beyond that white area ad searches the black area. I guess what I actually want help on is the following code.

$Coord= PixelSearch(500, 500, @DesktopWidth - 500, @DesktopHeight - 500, 0xB08978, 3)

So basically with the code above, what I think it should be doing is as follows:

1) 500 (500 pixels from the left)

2) 500 (500 pixels from the top)

both (1,2) should give me the top left corner of the rectangle

3) 500 (500 pixels from the right)

4) 500 (500 pixels from the bottom)

both (3,4) should give me the bottom right corner of the rectangle. Am I correct on this? is this how I would successfully what I want? because, when It runs, It doesn't seem to be right.

Share this post


Link to post
Share on other sites

from what i can tell, everything should work as you posted it.

you could make a complicated script to find the outlined black area (if it changes) but it would take a long time. instead just call it the way you did.

Share this post


Link to post
Share on other sites

Sorry, I thought my question said it all but after re-reading, I guess I missed a few things. First of all, it does work, but it doesn't. The white area in my OP is the area I want to search, but it goes beyond that white area ad searches the black area. I guess what I actually want help on is the following code.

$Coord= PixelSearch(500, 500, @DesktopWidth - 500, @DesktopHeight - 500, 0xB08978, 3)

So basically with the code above, what I think it should be doing is as follows:

1) 500 (500 pixels from the left)

2) 500 (500 pixels from the top)

both (1,2) should give me the top left corner of the rectangle

3) 500 (500 pixels from the right)

4) 500 (500 pixels from the bottom)

both (3,4) should give me the bottom right corner of the rectangle. Am I correct on this? is this how I would successfully what I want? because, when It runs, It doesn't seem to be right.

the only thing i can see that would make it search outside the given box is if autoit isnt reading the @DesktopWidth - 500 correctly. you might try putting some ()'s around it. like so

$Coord= PixelSearch(500, 500, (@DesktopWidth - 500), (@DesktopHeight - 500), 0xB08978, 3)

try it and see if the results r different.

Share this post


Link to post
Share on other sites

Are you sure that the pixel is in that area, the area searched in is 500 - 1180 by 500 - 550 (x and y) that's a relatively small area 680 pixels wide by 50 pixels tall.


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

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  
Followers 0