Moving mouse to a pixel with a specific color

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

Moving mouse to a pixel with a specific color

Post by guyash2 » Thu May 05, 2005 2:54 pm

Hi,
I am new at that forum, and new in the software :lol:
I tried to write some kind of a program but I didn't succeed to (and I didn't find the answer in te help topics of the software).
The progrm that I want to write needs to do as following: it recognizes when there is a pixel in the screen which have a defined and specific color and then it moves the mouse to this pixel and left click it. If there are some pixels with the same specific color the program will choose one of them (it doesn't matter which one of them).

Thank you very much :wink:

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Thu May 05, 2005 4:11 pm

Loop through all pixels on the screen looking for the color required and when found move the mouse to it. You will need two nested loops - one for X and one for Y coordinates.
MJT Net Support
[email protected]

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 » Thu May 05, 2005 4:38 pm

There is no command to do that. You will need to scan the screen pixel by pixel to do that.
Here is an example.
You will need to enter the values for pixelcolor(value), and resolutions columns(xcount) and rows(ycount)

Code: Select all

//Get pixel color
Let>value=12345678
Let>x=0
Let>y=0
Let>xcount=800
Let>ycount=600

Label>Loop
GetPixelColor>x,y,result
If>%result%=%value%,Found
If>%x%<%xcount%,NextColumn,NextRow

Label>NextColumn
Let>x=%x%+1
Goto>Loop

Label>NextRow
If>%y%=%ycount%,NotFound
Let>y=%y%+1
Let>x=0
Goto>Loop

Label>Found
Message>Color %value% located at %x%, %y%.
Goto>End

Label>NotFound
Message>Color %value% not found

Label>End
You may need to maximize window and/or reset the beginning x,y values for the particular window area that you want to cover. You may also need to change the reset values of x,y from 0 to a different value based on the area you are scanning.


[/quote]
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

10x

Post by guyash2 » Tue May 10, 2005 6:48 pm

Thank you but I haven't solved the problem yet. I was confused by the scan of the pixels so I tried to give the software specific colors that might be displayed in these specific pixels. The program should have to check if these colors are in this pixels and if they do, click them, but when I operate the software it doesn't click on anything, eventhough there are these colors on these pixels. what's wrong?

label>check
getpixelcolor>491,386,result
if>result=10012406,good1
getpixelcolor>585,389,result
if>result=11386317,good2
getpixelcolor>684,388,result
if>result=12175583,good3
getpixelcolor>493,444,result
if>result=5270938,good4
getpixelcolor>584,454,result
if>result=9158638,good5
getpixelcolor>689,463,result
if>result=11987455,good6
getpixelcolor>499,534,result
if>result=10144255,good7
getpixelcolor>587,527,result
if>result=3093199,good8
getpixelcolor>680,520,result
if>result=11067135,good9
wait>1
goto>check

label>good1
mousemove>491,386
lclick
goto>check

label>good2
mousemove>585,389
lclick
goto>check

label>good3
mousemove>684,388
lclick
goto>check

label>good4
mousemove>493,444
lclick
goto>check

label>good5
mousemove>584,454
lclick
goto>check

label>good6
mousemove>689,463
lclick
goto>check

label>good7
mousemove>499,534
lclick
goto>check

label>good8
mousemove>587,527
lclick
goto>check

label>good9
mousemove>680,520
lclick
goto>check

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 » Tue May 10, 2005 7:07 pm

How do you know that it does not click? Is this some type of button that will trigger an action?

You also loop back to checking again as soon as you click. so you may not enough time to see results. Maybe insert a Wait>5 after the lclick command.

Check the log to see if the lclick is actually being executed.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

Post by guyash2 » Tue May 10, 2005 7:30 pm

hmm.. this is lclick.. so it does trigger an action (or i didn't understand you well?)

and I inserted wait>5 after all lclick and it still doesn't work..:-/

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue May 10, 2005 7:37 pm

guyash2 wrote:hmm.. this is lclick.. so it does trigger an action (or i didn't understand you well?)

and I inserted wait>5 after all lclick and it still doesn't work..:-/
Not necessarily. It depends *WHERE* you LClick and on *WHAT*. E.g. if you left click on the desktop, what happens? Nothing.
MJT Net Support
[email protected]

guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

ok..

Post by guyash2 » Tue May 10, 2005 8:10 pm

ok.. but to be sure, where can I find the log of the software after she finished to work?

10x

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 » Tue May 10, 2005 9:20 pm

Re Log:

1. Save your macro

2. From the Macro Scheduler main window (Control Panel), right click on Macro Name, select Properties. Go to tab for Logging.

3. Put a check to Log Progress of Macro. Fill in other values as desired.
In lower section, I usually use the 2nd option to Log Entry before running script.

4. Save changes to properties. Run macro, Review Log using Control Panel Tool icons.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

ok..

Post by guyash2 » Wed May 11, 2005 2:08 pm

thanks alot, I understand now.
but I have anothr question: Is there a button or sequence of buttons which I click them and then it stops the macro?

10x alot

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed May 11, 2005 2:13 pm

To stop the macro you can do any one of the following:

- Press SHIFT-ESC or whatever combination you may have set under Tools/Options

- Click the Stop button

- Right click the system tray icon and select Break

- Select Run/Break from the main menu

- While in Macro Scheduler press Ctrl-B
MJT Net Support
[email protected]

guyash2
Junior Coder
Posts: 40
Joined: Thu May 05, 2005 2:45 pm

ok..

Post by guyash2 » Wed May 11, 2005 2:16 pm

thanks alot:) you helped me alot:)

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