Finding a pixel color in a certain area, then clicking it

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Wesman

Finding a pixel color in a certain area, then clicking it

Post by Wesman » Fri Apr 02, 2004 10:59 pm

Hello all,

I don't have alot of experience when it comes to stuff like this, so I'll explain this the best I can, and hopefully someone can make some sence out of it hehe.

Heres the situation. I need the program to look for a certain pixel color in a specific area, and once it finds it, click it. I know how to find the pixel color, and have already done so. The problem is that the pixel color I want it to click is in random spots and sometimes moving (but is in a "set" area that it won't move outside of.) I'd like to be able for the program to search for the pixel color (say every 8 minutes), click it if it locates it and continue on with the rest of the program. If it does not find it, it continues on with the rest of the program instructions until it's time (8 minutes later) to check for the pixel again.

I hope I've explained this somewhat well. If more information is needed, I'll do my best to explain the situation more. Thanks!

Wes

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Apr 03, 2004 4:45 am

Here's the concept, the code is up to you riight now

1. Define rectangle coordinates that includes pixel, ie TL-X,Y=30,30; TR-X,Y=60,30; BL-X,Y= 30,80; BR-X,Y=60,80.
2. Move mouse to TL-X,Y
Start Loop
3. Get Pixel Color
4. If Matches, Mouse LClick and continue to run desired routine.
5. If not match, Increase X by 1
6. If X>60, then x=30, Increase Y by 1
7. If Y>80, do something else and test again in 8 minutes
8. Move mouse to X,Y
9. Repeat loop

TL=Top Left, TR=Top Right, BL=Bottom Left, BR=Bottom Right
Beginning X,Y (TL=30,30) can be variables set at beginning of script. Or they could be calculated from some other known position. And the ending values (BR=60,80) could be calculated by adding Width and Height variables of the rectangle to the beginning values.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Wes

Post by Wes » Sat Apr 03, 2004 6:33 am

Thank you very much for the info. I think I'm getting what your saying. I'm just having a bit of trouble translating my thought into actual code. If it's not too much trouble, could I get an example of the above in code? I'm not very skilled in code work, but I like messing with this stuff hehe. I did some playing around with the concept above, but I seem to be using much more code than is needed, and I haven't been able to get a working code hammered out. Like I said, I understand the concept, but just can't quite get it out in the code.

Thanks again, your help has been very much appreciated!

Wes

Lumumba

Post by Lumumba » Sat Apr 03, 2004 8:10 am

Click --> here

BTW: there are > 100(0) postings available. Use the search! There's a good chance you'll stumble over something similar which would solve your issue. Thx. :wink:

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Apr 03, 2004 8:29 am

//Lines are from the sample I submitted to the forum
//This untested macro should allow you to see mouse movement and show
//message window displaying the X,Y values of the cursor.

//1. Define rectangle coordinates that includes pixel, ie TL-X,Y=30,30; TR-X,Y=60,30; BL-X,Y= 30,80; BR-X,Y=60,80.
//Provide Message Box to track real time progress.
Let>MSG_STAYONTOP=1

//Define Top Left (TL) position
Let>XTL=30
Let>YTL=30

//Define Rectangle dimensions
Let>Width=30
Let>Height=50

Let>X=%XTL%
Let>Y=%YTL%
Let>XMax=%X%+%Width%
Let>YMax=%Y%+%Height%

//Define color to look for
Let>FindColor=13160664

//2. Move mouse to TL-X,Y
//Start Loop
Label>FindPixel
MouseMove>%X%,%Y%

//3. Get Pixel Color
Label>MatchColor
GetPixelColor>%X%,%Y%,ThisColor

//4. If Matches, Mouse LClick and continue to run desired routine.
If>%ThisColor%=%FindColor%,Continue,NextX

//5. If not match, Increase X by 1
Label>NextX
Let>X=%X%+1

//6. If X>60, then x=30, Increase Y by 1
If>%X%>%XMax%,NextRow
Goto>NextSpot

Label>NextRow
Let>X=%XTL%
Let>Y=%Y%+1

//7. If Y>80, do something else and test again in 8 minutes
If>%Y%>%YMax%,NotFound,NextSpot

Label>NotFound
MessageModal>Color %FindColor% not found in this area
....Exit macro, do other things for 8 minutes and call macro again.

Goto>End

//8. Move mouse to X,Y
//9. Repeat loop
Label>NextSpot
Message>Moving mouse to X=%X% - Y=%Y%
Goto>FindPixel

Label>Continue
LClick
MessageModal>Color %FindColor% was found at X=%X% - Y=%Y%
...Do other things in the script

Label>End
This was quick and dirty based on my original outline.
No access to Macro Scheduler at the moment so this is theoretical, untested, but this should be enough to get you started.


Remember if you Cut/Paste from here to remove all Trailing Spaces.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Wes

Post by Wes » Sat Apr 03, 2004 5:55 pm

Thanks alot guys! It's working perfectly!

Wes

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