acantor Posted January 22, 2010 Report Share Posted January 22, 2010 (edited) I have a challenge for you all! There are occasions when the most reliable way to target a screen object is to "hunt" for a pixel colour that appears only in that object. For example, in the ME Pro Script Editor, in the default "M" icon to the left of the "Macro Nickname:" label, there is one pixel with colour = 7004146. (The "Mouse Locator" shows positions of the pointer as well as pixel color.) The AutoHotKey "PixelSearch" command is lightening fast, and easy to use. There is no equivalent command in Macro Express. I have put in a feature request. Hopefully, our friends at Insight will come through with a new command. But in the meantime, I need a way to search for a pixel in Macro Express. It was not horribly complicated to write a ME script to search for a pixel colour within a specified region (e.g., a rectangle). But my script runs slowly. For example, on my PC it takes 15 seconds to test a 400 by 400 pixel rectangle. AutoHotKey's PixelSearch chews through 1280 by 1024 pixels in under a second. I would welcome suggestions on how to make this kind of script run faster. If you are going to experiment with my script: 1. My script contains several disabled lines that I enable for testing. However, these lines are not disabled in the codebox. I suggest that you import the attachment. Otherwise, the script will run even more slowly than usual. 2. The macro that I exported is activated by Shift + Ctrl + Alt + \, which you may want to change. // Search a rectangular region of the screen for a pixel colour // Start at the top-left. Move right along a horizontal line, testing each pixel. At end of row, go to start of next line, and try again. // (Enable the disabled lines for testing and debugging) // Specify pixel colour to search for. Use "Mouse Locator" to obtain value, or use one of the values below... Variable Set Integer %PixelTarget% to 7004146 // This colour appears in the ME Pro Script Editor, in the "M" icon to the left of "Macro Nickname:" Variable Set Integer %PixelTarget% to -1 // This colour never appears. Enable this line to test for case when pixel cannot be found // Specify (x, y) of the top-left corner of the search rectangle... Variable Set Integer %xStart% to 0 Variable Set Integer %yStart% to 0 // Specify (x, y) of the bottom-right corner of search rectangle... Variable Set Integer %xEnd% to 400 Variable Set Integer %yEnd% to 400 // Calculate length and height of search rectangle: Variable Modify Integer: %xLength% = %xEnd% - %xStart% Variable Modify Integer: %yHeight% = %yEnd% - %yStart% // Set coordinate to test. (Start in upper-left corner)... Variable Set Integer %xCurrent% to %xStart% Variable Set Integer %yCurrent% to %yStart% // Start with the first "row" of pixels. We test up to yHeight rows... Repeat Start (Repeat %yHeight% times) // Test each pixel along a horizontal line xLength pixels long... Repeat Start (Repeat %xLength% times) Get Pixel Color at (%xCurrent%, %yCurrent%) Relative to Current Window into %PixelColour% Mouse Move: %xCurrent%, %yCurrent% Relative to Current Window // Use for debugging. Lets you see search progress, but it's slow! If Variable %PixelColour% Equals "%PixelTarget%" // Pixel found... Mouse Move: %xCurrent%, %yCurrent% Relative to Current Window Text Box Display: Found! Macro Stop Else // Increment x so we test next pixel to the right... Variable Modify Integer %xCurrent%: Increment End If // Continue until the entire row is tested... End Repeat // Reset x to its original value, and increment y so we can test pixels in the next row... Variable Set Integer %xCurrent% to %xStart% Variable Modify Integer %yCurrent%: Increment End Repeat // Pixel not found... Mouse Move: %xEnd%, %yEnd% Relative to Current Window Text Box Display: Not Found! Pixel_Search.mex Edited January 22, 2010 by Alan changed 'codebox' tags to 'code' tags to eliminate horizontal scrolling Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.