Moving mouse to a pixel with a specific color
Moderators: Dorian (MJT support), JRL
Moving mouse to a pixel with a specific color
Hi,
I am new at that forum, and new in the software
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
I am new at that forum, and new in the software
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
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]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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)
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]
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
[/quote]
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
10x
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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!
Bob
A humble man and PROUD of it!
Not necessarily. It depends *WHERE* you LClick and on *WHAT*. E.g. if you left click on the desktop, what happens? Nothing.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..:-/
MJT Net Support
[email protected]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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.
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!
Bob
A humble man and PROUD of it!
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
- 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]
[email protected]