Enthralled Posted December 30, 2008 Share Posted December 30, 2008 Hello, I am in the process of writing my first autoit script and I am running into some issues with the PixelGetColor function. Please look at the code snippet below: $curColor = PixelGetColor(MouseGetPos(0), MouseGetPos(1)) $hexCurColor = hex($curColor, 6) $curRed = _ColorGetRed($hexCurColor) $curGreen = _ColorGetGreen($hexCurColor) $curBlue = _ColorGetBlue($hexCurColor) ConsoleWrite(StringFormat("Current Color is %u %u %u \n", $curRed, $curGreen, $curBlue)) The issue is that the values displayed by this code are clearly wrong. To verify this I took a screen shot and opened it in paint to verify the pixel colors. In my test I had a section of the screen that was a clear green color with no blacks. However my code was displaying rbg values of 0 0 2 and 0 0 5, I would also see 0 0 234 and other clearly non-green values. In addition while these values will remain constant for a given mouse position they will change wildly with only a few pixels of movement while the screen color only has a gradual gradient to it. I am wondering if the hex conversion is rounding something off or if my output of the color values is incorrect in some way. When comparing my use of PixelGetColor to other scrips here I can not see anything obviously wrong. Any help or advice would be appreciated. I have attached a small example of the "greenish" color region I am mousing over on my screen. color_example.bmp Link to comment Share on other sites More sharing options...
TheTex Posted December 30, 2008 Share Posted December 30, 2008 (edited) I just took a quick look cause i'm tired but $curColor = PixelGetColor(MouseGetPos[0], MouseGetPos[1]) Notice the brackets Edited December 30, 2008 by TheTex Link to comment Share on other sites More sharing options...
Enthralled Posted December 30, 2008 Author Share Posted December 30, 2008 I just took a quick look cause i'm tired but $curColor = PixelGetColor(MouseGetPos[0], MouseGetPos[1]) Notice the brackets Thank you for taking the time to glance at it. MouseGetPos is a function call though, why would I use brackets? It takes an optional argument to return only the x or y cord rather than an array as it does by default. Link to comment Share on other sites More sharing options...
igotandrew Posted December 30, 2008 Share Posted December 30, 2008 Thank you for taking the time to glance at it. MouseGetPos is a function call though, why would I use brackets? It takes an optional argument to return only the x or y cord rather than an array as it does by default. Just from the help file Return Value Dimension Values None Returns a two-element array that containing the mouse coordinates: $array[0] = X coord (horizontal), $array[1] = Y coord (vertical) 0 Returns the X co-ordinate as an integer. 1 Returns the Y co-ordinate as an integer. Link to comment Share on other sites More sharing options...
Enthralled Posted December 30, 2008 Author Share Posted December 30, 2008 (edited) Just from the help file Return Value Dimension Values None Returns a two-element array that containing the mouse coordinates: $array[0] = X coord (horizontal), $array[1] = Y coord (vertical) 0 Returns the X co-ordinate as an integer. 1 Returns the Y co-ordinate as an integer. I am passing in args to avoid the array as a return value. Just in case this usage of MouseGetPos was an issue I modified my code to be the following: $mousePos = MouseGetPos() $curColor = PixelGetColor($mousePos[0], $mousePos[1]) $hexCurColor = hex($curColor, 6) $curRed = _ColorGetRed($hexCurColor) $curGreen = _ColorGetGreen($hexCurColor) $curBlue = _ColorGetBlue($hexCurColor) ConsoleWrite(StringFormat("Current Color is %u %u %u \n", $curRed, $curGreen, $curBlue)) As before the output is clearly wrong. Moving around the same greenish area I included in my original post gives this kind of output (sampling every 100 ms in a while loop): Current Color is 0 0 2 Current Color is 0 0 2 Current Color is 0 119 139 Current Color is 3 230 242 Current Color is 0 84 38 Current Color is 0 0 1 Current Color is 0 0 1 Current Color is 0 88 64 Current Color is 0 0 255 Current Color is 0 0 2 Current Color is 4 255 18 Current Color is 4 255 18 Current Color is 0 0 2 Current Color is 4 94 128 Current Color is 0 1 19 Current Color is 0 0 255 Current Color is 0 80 62 Current Color is 0 0 1 Current Color is 0 0 1 Current Color is 0 84 88 Current Color is 0 0 245 Current Color is 4 95 172 Current Color is 0 0 2 Current Color is 0 0 2 Current Color is 0 0 2 Edited December 30, 2008 by Enthralled Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now