Jump to content
Macro Express Forums

Little help with easy command


Recommended Posts

Hey I'm still figuring out this program but if any one could help script this simple task I would be very grateful.


Basically I want it to do this


1. Get color of pixel

2. Set Pixel color as N1

3. If pixel color isn't N1 then

4. Move mouse to x,y

5. left click

6. move back over to the N1 pixel

7. left click again

8. repeat these steps


Thanks in advance!

Link to comment
Share on other sites

You seem to have it figured out! Here's an outline:


(Optional 1: Text Box Display "Position Mouse in Desired Location then hit keyboard Enter to proceed"

...when you hit Enter the Text Box Display disappears and the macro continues)

Get Mouse Position into variables N5, N6 (to screen or window your choice)

Get Pixel Color at N5, N6 into variable N1

(Optional 2: Put current partial window title into variable T1)

Repeat Until ..... (your choice)

(Optional 2: Activate partial window title T1 + short time delay)

Get Pixel Color at N5, N6 into variable N2

If Variable N2 <> N1

Mouse Move N10,N11 (x,y to screen or window as above)

Mouse Left Click

Mouse Move N5, N6 (to screen or window as above)

Mouse Left Click

End If

Time Delay (how often the pixel color is checked)

Repeat End


I'm sure a number of small time delays will be required depending on how quickly the page changes after the mouse is clicked. If the Time Delay is long, you could also put it at the start of the repeat loop so that there is not a long delay after the final Mouse Click.


If you are monitoring a single pixel you cannot rely on the mouse staying exactly in place. That is why you save the mouse position as the first step and use the coordinates after that. I didn't debug the above.


When to stop the repeat is too dependent on your application. You can stop the macro manually or add some logic to do it.



If you don't want to bother with the Text Box Display you will have to position the mouse before running the macro.


If this is working unattended and particularly over long periods of time, you may need to add interlocks to ensure no other window is on top. I added the option of getting the current partial page title and activating before checking pixel color etc. This may not be needed if attended or short-term operation, and would be undesirable in high-speed checking (very short time delay). It may not work if the page title changes after the mouse click. That is why you use a partial title. Let's say it's Firefox, "Mozilla Firefox" is nearly always in every page title so you can ensure the browser is on top even though the full page title has changed.


Depending on application you may also be able to use change of page title rather than mouse color.


You may want to consider using the keyboard (Text Type) to do the necessaries at x, y (if it's a button) and more advanced, use Controls.

Link to comment
Share on other sites

You should be able to code it almost exactly as you have written it in English.

Assuming that the pixel you want to check is at coordinates 123, 456; and that

the other position you want to click is at 987,654; then this should do what you want.

Note that when coding Get Pixel and the Mouse Move commands, you will have to specify

whether the coordinates are relative to the whole screen, or relative to the window

that has focus.


Repeat Start (Repeat 2 times)

Get Pixel: Window Coords: 123,456 into %N1%

If Variable %N1% <> 123456789

Mouse Move Window 987, 654

Mouse Left Button Click

Mouse Move Window 123, 456

Mouse Left Button Click

End If

Repeat End


Here's the same macro in code format -- you should be able to copy and paste this

right into the script editor, and experiment with it from there.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...