Jump to content
Macro Express Forums

Waiting for pixel color to change


Recommended Posts

I used to know how to do this, but didn't document it. And now I couldn't find it here so let me try to ask again in this clearly VERY helpful forum.

Here's where I'm at

  • on a webpage, I am able to click on a box that gets me to the next page of a series through mouse moves (I can't reach it reliably through <Tab>s, because the number of <Tab>s to get there varies);
  • I now want to wait until a certain pixel on a page turns a certain color, and then end the macro
  • I tried putting this code at the end of of the (otherwise working) macroimage.png.06366ce5f8b042e18a6a1b7950bf6087.png, based on this information from the Mouse locator image.png.9c938966325b2496fa668ddafbd8d064.png'
  • this is to be a part of a sequence: 
    • my first macro ('Select 100 items') reliably (Tab, Tab, Tab) selects all 100 items on the screen and puts them in an online folder;
    • my second one (this one - 'Go to next page') is supposed to get me to the next page;
    • since the max N of items in the folder is 500, I want to repeat these two macros 5x
    • after that I have another reliable 'Tab-Tab-Tab'- macro that downloads the 500 items and clears the folder. But so on that one, I'd like to put a 'Wait until the activate window shows that pixel in that color', and then stop the macro. 

My questions:

  • is there a smarter way of putting the values for N[1] and N[2] in there than writing it down somewhere and entering it manually
  • does anybody have any idea why my 'Wait for pixel color'-keystrokes don't work
  • any other ideas for making this whole thing work reliable?

 

Thanks much!

Link to post
Share on other sites

I use that technique a lot.  It looks like your code should work.  If the macro isn't ending, are you sure the pixel is really changing to the color you want?  Since you are checking for location relative to the screen (not the window), a slightly different window position or a different screen resolution (different computer?) could cause this.  Also, sometimes certain shades on my screen will be made up of alternating pixel colors -- for example, getting a gray color by intermixing black and white pixels -- so if you are only one pixel off in location the test won't be reliable. 

 

For debugging purposes, put a Text Box Display inside the Repeat loop, right after the Get Pixel, displaying the N[2] value. 

 

Incidentally, I like to Repeat a set number of times -- then Repeat Exit when the desired color is detected -- rather than Repeat indefinitely like you are doing.  For example, Repeat 100 Times, with a delay of 100ms on each pass through the loop, allows a nominal 10 seconds for the color to appear, then ends the loop no matter what.  You can then check the color one more time, and display a message if it was not found.  Here's an example: when the Repeat loop ends, either successfully or because the attempts are exhausted, the last color found is checked again to determine whether the search was successful or not.

 

// Wait for "See Times" button to change color with mouse hovering over it
Mouse Move: 957, 270 Relative to Screen
Repeat Start (Repeat 100 times)
  Get Pixel Color from Beneath the Mouse into %N[1]%
  If Variable %N[1]% Equals "11355650"
    Repeat Exit
  Else
    Delay: 100 milliseconds
  End If
End Repeat
If Variable %N[1]% Equals "11355650"
  Mouse Left Click
  Macro Return
Else
  Text Box Display: Error
  Macro Return
End If

 

 

Link to post
Share on other sites

Agreed. Lose the infinite loop.

 

Another debugging aid: move the mouse pointer into position before checking the pixel colour beneath it.

 

Quote

Mouse Move: 1234, 5678 Relative to Current Window // Ensure the mouse pointer is directly on top of the target
Repeat Start (Repeat 100 times) // Wait up to 10 seconds for the pixel colour to appear
  Get Pixel Color from Beneath the Mouse into %PixelColour%
  If Variable %PixelColour% Equals "987654321"
    Mouse Left Click // The pixel colour was found!
    Repeat Exit
  End If
  Delay: 100 milliseconds
End Repeat

 

Link to post
Share on other sites

Hi,

Take care when defining the target position's pixel colour. Sometimes it changes by the very act of placing the mouse cursor over it. Possibly why your macro did not work. Instead of the built in Mouse Locator, use a simple macro that does not require the mouse, with the command

Get Pixel Color at (%x%, %y%) Relative to Screen into %PixCol%

 

Terry

 

 

Link to post
Share on other sites

Good point Terry, sometimes the pixel colour changes when hovering the pointer over an area of the screen.

 

Macro Express scripts run noticeably faster when checking colours via their coordinates rather than via the position of the mouse pointer. These scripts involve more math, but that's an advantage. Computers excel at doing mathematics, and are less good at constantly moving the mouse pointer!

Link to post
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...