Jump to content

PixelGetColor


Recommended Posts

I wrote a function that included the PixelGetColor operation. While testing, it performed the way it should have on some windows and not in others. The way that the function works is that if it reads a pure white pixel in (x, y) position, the function will return a value. For testing, I placed an open empty word document (the window is comprised of all white pixels) in the area where the PixelGetColor will be reading. The test returned the value it should have returned. However, when I opened a screenshot and placed it in the EXACT correct place, the funciton would not return the value after readign the white pixel. I've checked dozens of times to make sure the right pixel is in the right spot on my screen, and it still does not work. Any ideas why this demon function will not always work? :P

Link to comment
Share on other sites

  • Moderators

2 mistakes commonly made here with PixelGetColor() is

1. Assumption: Most new users will use the AutoInfo.exe Tool to get their coords, but leave the Coordinate Settings in the Options to Screen Coordinates, but ultimately, they are searching specific Window Coordinates, or a specific application Coordinate.

I would imagine you used Screen Coordinates, and when trying it on another computer or another resolution, the end-user moved the window, or did not have the same window resolution you wrote the script in.

So you need to Open AutoInfo.exe and go to Options / Coords and change them to either Client (that's what I use 95% of the time) or Window (the other 5%).

Then in your script, at the top of your script you should have these 2 lines.

Opt('PixelCoordMode', 0); 0 for window coords 2 for client
Opt('MouseCoordMode', 0); 0 for window coords 2 for client

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

2 mistakes commonly made here with PixelGetColor() is

1. Assumption: Most new users will use the AutoInfo.exe Tool to get their coords, but leave the Coordinate Settings in the Options to Screen Coordinates, but ultimately, they are searching specific Window Coordinates, or a specific application Coordinate.

I would imagine you used Screen Coordinates, and when trying it on another computer or another resolution, the end-user moved the window, or did not have the same window resolution you wrote the script in.

So you need to Open AutoInfo.exe and go to Options / Coords and change them to either Client (that's what I use 95% of the time) or Window (the other 5%).

Then in your script, at the top of your script you should have these 2 lines.

Opt('PixelCoordMode', 0); 0 for window coords 2 for client
Opt('MouseCoordMode', 0); 0 for window coords 2 for client
I can see that it could be a mistake where someone would use the coordinates from the screen when all they want is the coords from a specific window, leading to the program reading the wrong coord. I, however, want the function to read a pixel of a specific color that is in a specific place on MY screen. I wrote the function on my computer using the coords that are on my screen, and I have checked many times over that the screen coordinate and pixel color is correct. See, what I had done is taken a screenshot, pasted it in Paint and saved it. I then opened it with Windows Picture and Fax Viewer, hit ctrl+a so that it would be actual size, and alligned it perfectly so that the screen shot window looks flawlessly like a part of my desktop. Trust me, I have done this MANY times over in testing and debugging other programs, so I know that my method works. I did not move the program to another computer with a different resolution and someone else did not move the window. I KNOW that my function is reading the correct pixel on my screen and that the color it is reading is the same as the color to which my program is to respond. I have checked dozens of times to make sure that this is not a simple "got the coord wrong", "got the color wrong", "oops I changed the resolution" or "the window moved" problem. Those are all likely problems, but not in this specific case. I thank you for your good tip, but in this case, it's something else.
Link to comment
Share on other sites

  • Moderators

Those are all likely problems, but not in this specific case. I thank you for your good tip, but in this case, it's something else.

Then basically... Asking for a solution without posting the script for us to look at is like playing Russian roulette with a 6 shooter, all chambers being loaded and no chance of a misfire... The end result will always be the same :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Then basically... Asking for a solution without posting the script for us to look at is like playing Russian roulette with a 6 shooter, all chambers being loaded and no chance of a misfire... The end result will always be the same :P

haha yeah, im not very good at russian roullette, either... I always lose... But anyways, I figured otu what the problem was, and it was in a completely different part of the program. I thought the wrong part was misfiring. Thx for the help though!

Link to comment
Share on other sites

haha yeah, im not very good at russian roullette, either... I always lose... But anyways, I figured otu what the problem was, and it was in a completely different part of the program. I thought the wrong part was misfiring. Thx for the help though!

i understand that the pixel coords were not the ultimate issue here, BUT incase you have that kind of issue, or someone else looks to this thread for solutions to that type of issue. whenever i want to confirm that the pixel coordinates for a specific spot, i use a little script to verify.

while 1
    $pos = MouseGetPos()
    ToolTip($pos[0] & ", " & $pos[1] & @lf & PixelGetColor($pos[0],$pos[1]))
WEnd
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...