GetPixelColor Problem
Moderators: Dorian (MJT support), JRL
GetPixelColor Problem
I'm making a script that requires to GetPixelColor at more than one location at a time. (about 90 spots)
Is there an easy way to scan a group section of the screen and get the pixel color at coord's at:
X (340-380)
Y (272-316)
Without having to do it the long way? (eg)
GetPixelColor>340,272,GW
GetPixelColor>341,272,GW
GetPixelColor>342,272,GW
GetPixelColor>343,272,GW
... 90X later hehe
(and "if possible", avoiding a mousemove variable / script to get these results)
and example would be greatly appreciated!
Ken Jensen
Mobile Computer Service
Is there an easy way to scan a group section of the screen and get the pixel color at coord's at:
X (340-380)
Y (272-316)
Without having to do it the long way? (eg)
GetPixelColor>340,272,GW
GetPixelColor>341,272,GW
GetPixelColor>342,272,GW
GetPixelColor>343,272,GW
... 90X later hehe
(and "if possible", avoiding a mousemove variable / script to get these results)
and example would be greatly appreciated!
Ken Jensen
Mobile Computer Service
Hi,
Yes, of course. Use two loops - the outer loop for the X coords with a nested loop for the Y coords.
Yes, of course. Use two loops - the outer loop for the X coords with a nested loop for the Y coords.
MJT Net Support
[email protected]
[email protected]
Thats great! ... but thats the problem i'm having. I have no idea on how to loop it
I can loop a mousemove command.. but can't get it to work for GetPixelColor.
I'm missing something ...
If its not too much trouble (or too big of a script) any chance on an example to get me started?
Thanks again,
Ken Jensen
Mobile Computer Service
I can loop a mousemove command.. but can't get it to work for GetPixelColor.
I'm missing something ...
If its not too much trouble (or too big of a script) any chance on an example to get me started?
Thanks again,
Ken Jensen
Mobile Computer Service
Hi,
Take a look at the help topics for Repeat and Until and you will find an example of a loop using these commands. One of these loops inside another using different counters - say X and Y - is all you need.
Take a look at the help topics for Repeat and Until and you will find an example of a loop using these commands. One of these loops inside another using different counters - say X and Y - is all you need.
MJT Net Support
[email protected]
[email protected]
I must be doing something wrong.
My script will read the X coords, but wont move or read the Y position.
Label>Begin
MouseMoveRel>340,272
Label>Start
GetCursorPos>X,Y
Let>X=X
Repeat>X
GetPixelColor>X,Y,S
Let>X=X+1
If>%S%=8116190,Ready
If>%X%>380,Start1
If>%Y%>316,Begin
Until>X,382
Goto>Start
Label>Start1
Let>X=X-40
Let>Y=Y+1
Goto>Start
Label>Ready
...
....
and ideas?
My script will read the X coords, but wont move or read the Y position.
Label>Begin
MouseMoveRel>340,272
Label>Start
GetCursorPos>X,Y
Let>X=X
Repeat>X
GetPixelColor>X,Y,S
Let>X=X+1
If>%S%=8116190,Ready
If>%X%>380,Start1
If>%Y%>316,Begin
Until>X,382
Goto>Start
Label>Start1
Let>X=X-40
Let>Y=Y+1
Goto>Start
Label>Ready
...
....
and ideas?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
I think the major problem is GetCursorPos> which will reset the calculated value of Y. But here are some additional notes:
=========================
MouseMoveRel moves you to a screen position relative to a window. Get CursorPos gets back actual screen position, not the relative window position. So X position can already be >380 or Y could be greater than 316 before you start. That will be a problem.
==========================
Try these steps:
1.
Only do GetCursorPos> at the beginning to get initial values. Then use those those values to calculate area width and height positions:
GetCursorPos>X,Y
Let>MaxX=%X%+40
Let>MaxY=%Y%+44
2.
Change the 380, 316, to the values calculated above:
If>%X%>%MaxX%,Start1
If>%Y%>%MaxY%,Begin
3.
Remove the line Let>X=X( not needed).
Move the Label>Start below the line GetCusorPos>
to avoid getting Cursor Position again (Resets your just calculated x and y values, and what if mouse moves?
4.
Change Until to calculated value
Until>X,%MaxX%
=====================
Here is my version of that routine. I have added a message window to monitor the X,Y changes.:
This will run forever until %GoodColor% is located. For test purposes, change value of GoodColor to a value you know is there. You can get that by watching the Message Window or looking at log results to see what colors are in the actual area being monitored.
Hope this helps, good luck......
=========================
MouseMoveRel moves you to a screen position relative to a window. Get CursorPos gets back actual screen position, not the relative window position. So X position can already be >380 or Y could be greater than 316 before you start. That will be a problem.
==========================
Try these steps:
1.
Only do GetCursorPos> at the beginning to get initial values. Then use those those values to calculate area width and height positions:
GetCursorPos>X,Y
Let>MaxX=%X%+40
Let>MaxY=%Y%+44
2.
Change the 380, 316, to the values calculated above:
If>%X%>%MaxX%,Start1
If>%Y%>%MaxY%,Begin
3.
Remove the line Let>X=X( not needed).
Move the Label>Start below the line GetCusorPos>
to avoid getting Cursor Position again (Resets your just calculated x and y values, and what if mouse moves?
4.
Change Until to calculated value
Until>X,%MaxX%
=====================
Here is my version of that routine. I have added a message window to monitor the X,Y changes.:
This works for me but I am sure you will need to modify it for your needs. This has no mouse movements. I have put variables at start of script to make it easy to modify area and color being monitored.Label>MacroVariables
// H and V are relative Horizontal and Vertical offsets of Window origin.
Let>H=340
Let>V=272
//Width and Height are pixel counts of area being scanned
Let>Width=40
Let>Height=44
//GoodColor is value of color that will jump to Label>Ready
Let>GoodColor=8116190
Label>Begin
MouseMoveRel>%H%,%V%
GetCursorPos>X,Y
Let>MaxX=%X%+%Width%
Let>MaxY=%Y%+%Height%
Label>Start
Repeat>X
GetPixelColor>X,Y,S
Message>Color at %X%, %Y% is %S%.
Let>X=%X%+1
If>%S%=%GoodColor%,Ready
If>%X%>%MaxX%,Start1
If>%Y%>%MaxY%,Begin
Until>X,%MaxX%-1
Goto>Start
Label>Start1
Let>X=%X%-%Width%
Let>Y=%Y%+1
Goto>Start
Label>Ready
This will run forever until %GoodColor% is located. For test purposes, change value of GoodColor to a value you know is there. You can get that by watching the Message Window or looking at log results to see what colors are in the actual area being monitored.
Hope this helps, good luck......
Last edited by Bob Hansen on Wed May 07, 2003 8:21 pm, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
I wonder if it's possible to take this one step further ..
In my script below, I have in bold MouseMoveRel>340,272
(Which is my start point of the search for the matching pixel color)
Once it finds my color, it goes to Label>Ready.
After MouseMoveRel>X,Y & LClick it goes back to Label>Macro.
(which is important that it does this & at the very start of the script)
Is there a way to make the script NOT go back to 340,272 start point until it has completed its scan of the whole area while continuing to LClick?
I was thinking of adding at the end of Label>Ready
Let>X=%J%
Let>Y=%K%
and do a call for the last coords it was at with a
MouseMoveRel>%J%,%K%
but with that MouseMoveRel>340,272 as my start point.. it messes things up.
Is this possible? or is this just wishful thinking.
Label>Macro
MouseMoveRel>100,200 (example coords)
LClick
Label>Begin
MouseMoveRel>340,272
GetCursorPos>X,Y
Label>Start
Let>X=X
Repeat>X
GetPixelColor>X,Y,S
Let>X=X+1
If>%S%=8116190,Ready
If>%X%>380,Start1
If>%Y%>316,Begin
Until>X,382
Goto>Start
Label>Start1
Let>X=X-40
Let>Y=Y+1
Goto>Start
Label>Ready
MouseMoveRel>X,Y
LClick
Goto>Macro
Thanks,
Ken Jensen
Mobile Computer Service
In my script below, I have in bold MouseMoveRel>340,272
(Which is my start point of the search for the matching pixel color)
Once it finds my color, it goes to Label>Ready.
After MouseMoveRel>X,Y & LClick it goes back to Label>Macro.
(which is important that it does this & at the very start of the script)
Is there a way to make the script NOT go back to 340,272 start point until it has completed its scan of the whole area while continuing to LClick?
I was thinking of adding at the end of Label>Ready
Let>X=%J%
Let>Y=%K%
and do a call for the last coords it was at with a
MouseMoveRel>%J%,%K%
but with that MouseMoveRel>340,272 as my start point.. it messes things up.
Is this possible? or is this just wishful thinking.
Label>Macro
MouseMoveRel>100,200 (example coords)
LClick
Label>Begin
MouseMoveRel>340,272
GetCursorPos>X,Y
Label>Start
Let>X=X
Repeat>X
GetPixelColor>X,Y,S
Let>X=X+1
If>%S%=8116190,Ready
If>%X%>380,Start1
If>%Y%>316,Begin
Until>X,382
Goto>Start
Label>Start1
Let>X=X-40
Let>Y=Y+1
Goto>Start
Label>Ready
MouseMoveRel>X,Y
LClick
Goto>Macro
Thanks,
Ken Jensen
Mobile Computer Service
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
You ask:
If you want to continue to scan the entire area, then remove the jump to Ready. Maybe record the positions and continue in the same loop?
If you change the bolded MoveMouseRel command to MoveMouseRel>%X%,%Y%, then you can seed the begining of the script with Let>X=340 and Let>Y=272. Now when you run the script, it will scan till it finds the color, continue scanning the remaining area starting where it left off, and continue process untill the entire area is scanned. You may have to add 1 to your X or Y value before you jump back to Label>Begin so you don't look at the exact same pixel where you had the match.
If this was confusing, sorry, but as I noted, I am confused also about what you are trying to do.
Hope this helps, good luck...........
I am confused. Once it finds the color, it stops scanning the area defined. You never get to the Label>Ready until you have completed scanning the entire area or until you find the designated color, which comes first.Is there a way to make the script NOT go back to 340,272 start point until it has completed its scan of the whole area while continuing to LClick?
If you want to continue to scan the entire area, then remove the jump to Ready. Maybe record the positions and continue in the same loop?
If you change the bolded MoveMouseRel command to MoveMouseRel>%X%,%Y%, then you can seed the begining of the script with Let>X=340 and Let>Y=272. Now when you run the script, it will scan till it finds the color, continue scanning the remaining area starting where it left off, and continue process untill the entire area is scanned. You may have to add 1 to your X or Y value before you jump back to Label>Begin so you don't look at the exact same pixel where you had the match.
If this was confusing, sorry, but as I noted, I am confused also about what you are trying to do.
Hope this helps, good luck...........
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
I probably could of explained myself a little better, but you answered my question.
I have an idea on what i can do now.
I just need to change my script around to follow closer to your example
(using more of the variables)
Thank you very much for taking the time to help me with this script the last couple days.
Ken Jensen
Mobile Computer Service
I have an idea on what i can do now.
I just need to change my script around to follow closer to your example
(using more of the variables)
Thank you very much for taking the time to help me with this script the last couple days.
Ken Jensen
Mobile Computer Service