WaitPixelColor problem

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Thu Sep 22, 2005 5:59 am

Rain,

Thanks for your post. You suggestion to set the window to
coordinate 0,0 I consider directed at myself.

I perceived or understand from the Macro Scheduler command
and help that MouseMoveRel is intended to free the user from
"hard coordinates" so the mouse cursor or pointer will go to
to same relative location in the window regardless how it is
sized. In my Macro Scheduler application I maximize the
window to get a standard window or reference even though
(I guess) theoretically I shouldn't have to so long as the
window is in focus (?).

What's throwing me for a loop (no pun intended and again I
hope I'm explaining myself so I can be understood) I send
the mouse pointer/cursor (doing a MouseMoveRel) to a section
of the screen that's white, I do a GetPixelColor and get a
return of a number that represents white.

This initial MouseMoveRel is the start of a loop where I increment
the mouse move by "1 relative row", so if my initial relative
coordinate is 300,190 my next GetPixelColor is at 300,191
then 300,192 etc. In my application I'm looking for a return
of a number that represents "blue" and in another range
"aquamarine" ... noooo problem. I go through the loop and
get "pixel color number returns" of white, black (text) and my
"loop if" is looking for "blue" ... in fact on ww.Bluesq.com once
you previously select a link for a race track it goes to a different
shade of blue and in this case there is a pixel color differention
(return) which my loop "recognizes".

In my relative loop once I hit the "initial shade of blue" I have
the link selected from my relative mouse move, do a LClick and
Viola! the link is selected just as I want.

However, the same relative thing (again no pun intended) on the
light/dark gray scroll bar ... no Pixel color differentiation. It seems
in most cases the differentiation works just fine ... but in this
case not.

Just thinking out loud could it be one Pixel Color return from
Macro Scheduler includes a range of shades of a given color
and the shades of blue is enough of a color difference in my
loop for a different GetPixelColor return?

Again hope I'm making some sense here. I guess I can show
my actual Macro Scheduler code (which I don't have access to
as I write this post from another computer) but I don't know if
it really is that important unless someone'd would be willing to
see for themself.

Thanks,

Joel.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Sep 22, 2005 12:04 pm

Hi Joel,
There is no color chart that I know off but if you want to post your script and explain to me what your trying to do I will take look at it. :)

Rain

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Sep 22, 2005 4:06 pm

Rain wrote:Hi Joel,
There is no color chart that I know off but if you want to post your script and explain to me what your trying to do I will take look at it. :)

Rain
The MacroScheduler macro create window will display the coordinates and pixel color at the mouse pointer (it's an option on the pulldown menu to the right of the Macro Name box).

Image

But sometimes it's very difficult to get that window on top of the application you are trying to automate so you can also use Colorpic http://www.iconico.com/colorpic/index.aspx which is a useful and free application that displays the numerical value of the pixel at the mouse cursor, the same number that would be returned by getpixelcolor (and also the hex value for HTML coding). So you can open the application or webpage you are trying to automate and mouse over the location of interest, copy the value displayed by colorpic and use it in your macro.

User avatar
JRL
Automation Wizard
Posts: 3502
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 22, 2005 4:37 pm

You can get a similar funtionality from the "Tools" menu in the Macro Scheduler editor. There is an item called "Cursor Monitor" and while it is checked, YOUR cursor will display the current x, y coordinates and the associated pixel color. Check it out, it works well.

Later,
Dick

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Thu Sep 22, 2005 5:42 pm

I was talking about a chart that gives a range of different chades of gray, red, blue etc.

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Thu Sep 22, 2005 7:54 pm

Rain, Me Again, All ...

Thanks again for replying and helping work through this pixel
color issue.

Following are two similarly functioning sections of my code
of the "window range" I described. For Bluesq.com the inital
relative window "mouse cursor row" is 350 loop until 550.
For the Betfair.com the inital mouse cursor row is 175 looping
until 470. So the window range is relative mouse row ranges
are 175 to 470 and 350 to 500 respectively.

As you can see I'm looking for color 9974784 for Bluesq.com and
16777215 for Betfair.com

These two loops work fine for me ...

However, If I do a similar loop as these two on Betfair scroll bar
there is no Pixel color differentiation from dark gray scroll bar
button to the light gray scroll bar track - at least on my computer.

Hope this puts it a little more in perspective.

Thanks Again,

Joel S.


Remark>Initial Bluesq
Let>Ctr6=350

.
.
.

MouseMoveRel>326,182
Wait>1.0
MouseMoveRel>324,206
Wait>1.0
LClick
Wait>5.0
Label>OdTrack
Repeat>Ctr6
Let>Ctr6=Ctr6+1
MouseMoveRel>192,%Ctr6%
GetPixelColor>192,%Ctr6%,PC
If>%PC%=9974784
GoTo>Sel
EndIf
Until>Ctr6=550
Remark>
Remark>========================
Remark>=== Page Down BlueSq ===
Remark>=========================
Remark>
Remark> Blue Sq Page Page Down Code Here (Future)
Remark>
Label>Sel
Wait>5.0
LClick
Wait>20.0
Press Ctrl
Send Character/Text>ac
Release Ctrl

.
.
.

Remark>
Remark>=========================
Remark>=== See if a UK track ===
Remark>=========================
Remark>
Label>Anchor
Let>Ctr3=175
Repeat>Ctr3
Let>Ctr3=Ctr3+1
MouseMoveRel>125,%Ctr3%
GetPixelColor>125,%Ctr3%,PC
If>%PC%16777215
GoTo>NoSelect
Else
Wait>2.0
LClick * 2
If>%Flag1%=0
Let>Flag1=1
Wait>15.0
EndIf
.
.
.
.
Label>NoSelect
Until>Ctr3=470

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Thu Sep 22, 2005 8:20 pm

Rain, Me Again, All ...

A couple of finer points if I could for duplicating
my pixel issue from my previous post (terrible grammar
in my previous post - note to myself spell and grammar
check better)

Once you have BlueSq web page up the following
"hard coordinates" select Racing and then UK racing

In my two loops as the relatively mouse cursor incrementally
goes down the range (Relative Mouse Cursor/Pointer row
to the next) once the cursor hits the link it changes color.
Thankfully the pixel color changes faster than the "natural
loop" or the increment of the next "relative mouse row".

If it didn't or perhaps doesn't on another computer
all needs to be done is put a Wait> in in the same
respect I have 1.0 second waits in the hard coordinates.

This should not be a factor in the gray slidebar - there should
be plenty of time to discern a dark gray and light gray Pixel
color differentiation.

Joel.


MouseMoveRel>326,182
Wait>1.0
MouseMoveRel>324,206
Wait>1.0
LClick
Wait>5.0

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Sep 23, 2005 2:39 am

I looked at the bluesq site. Are you talking about the scroll bar on the right hand edge of the IE window? If so there are a lot of shades of grey in there but the edge is solid and detectable as 11312797 so you could scan down the middle until you detect the bottom edge and back up a few pixels. Or why not use the down arrow instead of trying to hit the scroll bar? Or maybe I've just missed the whole point ?

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Fri Sep 23, 2005 5:52 am

Me Again ...

Thanks for your help.

In terms of where my immediate scroll bar issue is, it isn't on
http://www.Bluesq.com but on http://www.betfair.com. On initially bringing up
http://www.betfair.com you'll see on the left hand side a frame for
the markets, different sports etc.

Select Horse Racing - Today's Races.
On selecting this option another window comes up with a frame
in the same relative location showing many races worldwide
"carried" by http://www.betfair.com.

Put your mouse cursor/pointer on a race selection at the top of
the frame and slide it down relatively slowly. Notice the different
races turn aquamarine as soon as the cursor is perceived as
passing the black cell border that delineates one race from
another.

The aquamarine is my target - As soon as Macro Scheduler
recognizes the aquamarine color I select it and determine if
it is a race I want to consider in the future.

I do an initial pass stepping through all the races in the frame.
When I get to the bottom of the frame what I want to do is a
Page Down of the frame. This is accomplished by single clicking
in the scroll bar track at the bottom very near the down arrow but
but not actually within the down arrow.

This tabbing is scaled so however many races there are the
scroll slide bar won't reach the bottom until I'm at the end of
the race list. At that point I have my mouse cursor in a
position where I should be "reading" the dark scroll button
using GetPixelColor instead of the light gray of the track. My
mouse cursor is positioned right in the middle of the scroll
bar track. So theoretically as soon as Macro Scheduler recognizes
the dark gray I/it knows it's done with the initial "big pass".
This was/is my first choice of determining the end of the pass.

The work around I do is identify the color of the bottom cell
after a page down. If it remains aquamarine I know I'm done
with my pass. This is kind of tricky as if you do a scroll down
with the slide bar the bottom race cell of the frame is not
always a full cell. Luckily when I do a page down the aquamarine
is "carried" to the top of the frame. If I place my cursor too close
to the bottom of the frame for the aquamarine determination I
stand the chance of hitting the black border of a race cell.

Again I hope my description makes some semblance of sense.
It just gnaws at me there should be a differentiation of Pixel
color recognition between the light and dark gray shades of the
dark gray scroll bar slide button and the light gray track in
http://www.betfair.com

Thanks Again Me Again,

Joel.

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Fri Sep 23, 2005 6:10 am

To Clarify my previous post. On my work around I have a
full race cell that is aquamarine near the bottom of the frame
when I do a "page down" the race cell is "carried" to the
top of the frame aquamarine color still intact. However ...
(uh boy this is tough for me to explain ...) when the aquamarine
cell is not showing at the top of the frame I know from experience
what is showing is the next race. My Macro Scheduler script
takes this all into consideration and it proved not to be that
hard.

Identifying aquamarine, different shades of blue, white, black ...
noooo problem ... different shades of gray: problem.

Joel.

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Fri Sep 23, 2005 11:00 am

Looks like you have to be a member in order to get the different link colors you're talking about but since I live in the US it's not letting me sign up.
Why not use Press Page Down when the cursor has reached the bottom then start searching from the top again?
I've played around for a few minutes and came with the script bellow which seems to be working fine. It looks for the blue in the (:) of the time, when it finds the blue color the script moves the mouse to the link and reads the color again. If target color is found (Aquamarine) the script will go to ClickLink, if not the script will keep searching till it reaches the last link/race, press page down and start searching all over again from top to bottom.

label>Start
let>X=37
let>Y=235
label>FindLinkLoop
wait>.0005
add>Y,1
GetPixelColor>X,Y,Color
if>Color=10902281,LinkFound
if>Y>655,PageDown
goto>FindLinkLoop
label>LinkFound
MouseMove>X,Y
wait>.2
GetPixelColor>X,Y,Color
if>Color=Aqua,ClickLink
goto>FindLinkLoop
label>PageDown
SetFocus>Betfair - *
Press Page Down
wait>.5
goto>Start



Note if you want to try my script
You may have to change the X Y cords in line 2 and 3, get the cords of (:) in the time. Line 9 (if>Y>655,PageDown) adjust it to the cords of the last race on the page.
Last edited by Rain on Mon Sep 26, 2005 10:30 am, edited 1 time in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Sep 23, 2005 3:18 pm

Thanks for the clarification, I'll take a look later, I can't be playing on those sites during the day - if you know what I mean :lol:

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Sat Sep 24, 2005 5:00 am

Rain, Me Again,

Much appreciated for your help with the script solution
and in general. Your solution (just looking at it) appears
better; more reliable and elegant than my own. Very
good suggestions. For what it's worth if you're interested
in my arbitrage idea I would be happy to share some of
my code with you in terms of other aspects of my solution
offline (other Macro Scheduler script I developed and Excel
VB macros but all under Macro Scheduler control or
supervision) not only as a token of my appreciation but also
with the understanding that different solutions from others
ultimately make for a more robust application (like open
source Linux) that's inherently tricky and in need of constant
attention ... what if betfair.com and/or bluesq.com
suddenly decide to change the entire format of their web
pages. But it is an app that from context one that's
inherently profitable unless the book doesn't pay off and or
some miscalculation has been made where the payoff
somehow is less than expected and IMHO one that's
interesting.

I'll let you know my progress as soon as I implement it.

Joel.

JRS
Pro Scripter
Posts: 71
Joined: Thu Nov 04, 2004 5:19 am

Post by JRS » Sat Sep 24, 2005 5:19 am

Rain, Me Again, All ...

One quick note in addendum ... this arbitrage idea at least
from my research has a few (but unfortunately not that
many) other areas where it can be applied instead of
horse racing / sports wagering.

One is currency exchange where you convert currency from
one country's to another and (hopefully) after all the service
charges from each exhange you wind up with a profit.

However, in any arbitrage scenario you have certain
quantities that keep changing value in a stream and the
idea is to catch the values just at the right times and make
hay while the sun shines.

No better a tool than Macro Scheduler to realize this.

Joel.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Sep 24, 2005 2:00 pm

Now I got into betfair I agree with Rain's method, page down seems to be reliable.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts