Jump to content
Macro Express Forums

Click ONLY on pixel change


fug5333

Recommended Posts

Having some issues. :( Trying to move the mouse to a specific spot, when the color changes, click the mouse. Then do the same thing 3 more times. This is what I have so far

 

Mouse Move Windows 747, 682

Delay 100 Milliseconds

Mouse Left Button Click

Repeat Until %N1% = 16777215

Get Pixel: Window Coords: 747, 682 into %N1%

If Variable %N1% = 16777215

Mouse Left Button Click

Delay 100 Milliseconds

 

----- Works as expected so far -----

 

Repeat Until %N2% = 215

Get Pixel: Window Coords: 783, 651 into %N2%

If Variable %N2% = 255

Mouse Left Button Click

End If

Repeat End

End If

Repeat End

 

 

 

It never does the second click. It just sits there. :( I need it to actively check a certain coordinate for a pixel change, click, then do that 3 more times. "Repeat Until" seemed like that would be the way to go. Any ideas!

 

Thanks

Link to comment
Share on other sites

Try this:

 

// First click

Mouse Move Windows 747, 682 // Where to click 1

Delay 100 Milliseconds

Mouse Left Button Click

//

// Second click

Mouse Move Windows 747, 682 // Where to click 2

Repeat Until %N1% = 16777215

Get Pixel: beneath the mouse into %N1%

End Repeat

Mouse Left Button Click

Delay 100 Milliseconds

//

// Third click

Mouse Move Windows 783, 651 // Where to click 3

Repeat Until %N1% = 215

Get Pixel: beneath the mouse into %N1%

Repeat End

Mouse Left Button Click

Delay 100 Milliseconds

 

I am not convinced that the delays are needed, so try removing them once the macro is working.

Link to comment
Share on other sites

Hmm. Might be tough to explain. All four clicks are in the same spot, the pixel under the mouse for 1 and 2-4 are in different places. I'll explain it simply:

 

Move Mouse x,y

when the pixel changes, click left mouse button

Check another location but keep mouse in same spot

when pixel changes, click left mouse button

 

 

Do the last 2 lines a total of 3 times. It's exactly the same. I'm trying to turn that into a macro, something automated. I'm hung up on the syntax/code of ME. I hope all that made more sense.

 

Thanks!

Link to comment
Share on other sites

The logic looks OK, but your second block of code has a discrepancy between color 215 and color 255. Which color are you really looking for? Could that be the problem?

 

Repeat Until %N2% = 215

Get Pixel: Window Coords: 783, 651 into %N2%

If Variable %N2% = 255

Mouse Left Button Click

End If

Repeat End

 

Even after you fix that, it is possible that Windows will treat the two distinct mouse clicks as a double-click. 100ms delay might not be enough. Other than a longer delay, another way to avoid the double-click interpretation is to move the mouse to a second location for the second click. I know you want to click in the "same" place, but maybe moving it a few pixels one way or another will still qualify as the same. For example, if I manually position the mouse over a file name in Windows explorer, and run the following macro, it acts as a double-click and opens the file. However, if I have the macro move the mouse 10 pixels to the right prior to the second click, the two clicks are treated as two clicks and the file does not open, and the delay can be removed from the macro.

Mouse Left Button Click

Delay 100ms

Mouse Left Button Click

Link to comment
Share on other sites

These kinds of macros are notoriously challenging to script, especially if they run in a web browser.

 

My advice is to build the macro step by step. After you get the first part to work, test repeatedly, and try to make it fail. Then add one more step. Don't hesitate to change your scripting approach; usually there are many ways to automate a process, and some may prove to be more reliable than others. Expect to be picking away at the problem for a long time before you have success. If this is your first attempt at this kind of macro, you probably won't crack it right away. But as it is written in the I Ching, "Perseverance Furthers."

 

Approaches that I have found helpful when developing macros that monitor pixel colour changes in Web browsers include:

 

1. I find it more reliable to position the mouse cursor over the pixel at (x, y) than to monitor the (x, y) coordinate without the mouse cursor. The reason is that colours may be different when the mouse is hovering over than when it is not.

 

2. Reliability trumps elegance. You are correct that "Repeat Until" is the way to go, but it has downsides. What if the condition never occurs, as happens all too frequently when network bottlenecks prevent webpages from loading? You may find that it is more reliable to use "Repeat Count" instead, and check the target pixel for, say, 30 seconds (which might be 5000 or 10,000 loops). If you do it this way, it is easy to insert messages that indicate at what step things went wrong.

 

3. When checking pixel colours in a repeat loop, I sometimes find it necessary to insert a short delay; in other contexts, the delays are unnecessary; and once in a while, relatively long (1000-1500 ms) delays are essential. You can only find out through trial and error experimentation.

 

4. As rberg suggests, "nudging" the mouse pointer a few pixels back and forth sometimes helps. As above, it takes experimentation to figure it out.

 

Good luck with it!

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.

Guest
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.

Loading...
×
×
  • Create New...