Jump to content
Macro Express Forums

Color Detection


fug5333
 Share

Recommended Posts

I want to make a macro that will start at a set x,y coord, check that pixel color, if "X", then do "this", if not, move to the next pixel (x+1,y), and start over. When it gets to the end go back to the start and do (x,y+1) to move to the next row. Here's what I've got so far:

 

Mouse Move Window 366, 267 //Move the mouse to the start point

Get Mouse Position Window: %N1%, %N2% //Put the mouse coords into variables

Repeat Start (Repeat 759 times) //The pixels of one row

Get Pixel: Under Mouse into %N3%

Get Mouse Position Screen: %N4%, %N5%

If Variable %N3% = 43775 //The color I want

Mouse Left Button Click

Delay 250 Milliseconds

Mouse Move Position 0, 60

Mouse Left Button Click

Mouse Move Screen %N4%, %N5%

Else

Mouse Move Screen%N1%, %N2%

End If

Repeat End

 

Whew. The mouse (quickly) moves to the start position, then to the right one pixel, then to the left one pixel and stops. Any help would be great!

Link to comment
Share on other sites

I want to make a macro that will start at a set x,y coord, check that pixel color, if "X", then do "this", if not, move to the next pixel (x+1,y), and start over. When it gets to the end go back to the start and do (x,y+1) to move to the next row. Here's what I've got so far:

 

Mouse Move Window 366, 267 //Move the mouse to the start point

Get Mouse Position Window: %N1%, %N2% //Put the mouse coords into variables

Repeat Start (Repeat 759 times) //The pixels of one row

Get Pixel: Under Mouse into %N3%

Get Mouse Position Screen: %N4%, %N5%

If Variable %N3% = 43775 //The color I want

Mouse Left Button Click

Delay 250 Milliseconds

Mouse Move Position 0, 60

Mouse Left Button Click

Mouse Move Screen %N4%, %N5%

Else

Mouse Move Screen%N1%, %N2%

End If

Repeat End

 

Whew. The mouse (quickly) moves to the start position, then to the right one pixel, then to the left one pixel and stops. Any help would be great!

 

I'm not clear why your Mouse Move commands aren't consistently relative to either window or screen? Unless you're 100% sure they are identical (and remain so under all conditions) then why not use one or the other?

 

Where are the moves to (x+1,y) and (x,y+1) that you describe?

 

There are no window activation commands so I assume there are no possible changes in window focus?

 

It woud be better to post the code also, so that others could try it (even though it would obviously need adaptation).

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Inside your Repeat loop is the place to increment the x-coordinate, though as Terry points out, the increment is not being done (N1 = N1 + 1). You can enclose this loop in another Repeat loop where you increment the y-coordinate (and reset x to the original value) after each set of 759 "horizontal" checks.

 

If you don't explicitly want to watch the mouse move, the macro will run much faster if you check pixel color "at x/y coordinates" rather than "under mouse". Move the mouse only when you need it at a specific location in order to click. It is handy when debugging to move the mouse to each pixel-check position, so you get a visual of what the macro is doing. But then deactivate the mouse-move instruction or remove it once all is working right.

Link to comment
Share on other sites

I'm not clear why your Mouse Move commands aren't consistently relative to either window or screen? Unless you're 100% sure they are identical (and remain so under all conditions) then why not use one or the other?

 

Where are the moves to (x+1,y) and (x,y+1) that you describe?

 

There are no window activation commands so I assume there are no possible changes in window focus?

 

It woud be better to post the code also, so that others could try it (even though it would obviously need adaptation).

 

--

Terry, East Grinstead, UK

 

 

Window/Screen should be the same, but just for debugging, I can change to all be the same.

 

<MMW2:366,267><MOUSEPOS:F:01:02><REP3:01:000001:000001:00759:0:01:><MMP2:1N,2N><TBOX4:T:1:CenterCenter000278000200:000:color%N4%
%N5%
%N3%><GETPXM:3><MOUSEPOS:F:04:05><IFVAR2:2:03:1:43775><LCLK><MSD:250><MMP2:0,60><LCLK><DIS:<MMS2:4N,5N><ELSE><MMW2:1N,2N><ENDIF><ENDREP>

Link to comment
Share on other sites

Window/Screen should be the same, but just for debugging, I can change to all be the same.

 

<MMW2:366,267><MOUSEPOS:F:01:02><REP3:01:000001:000001:00759:0:01:><MMP2:1N,2N><TBOX4:T:1:CenterCenter000278000200:000:color%N4%
%N5%
%N3%><GETPXM:3><MOUSEPOS:F:04:05><IFVAR2:2:03:1:43775><LCLK><MSD:250><MMP2:0,60><LCLK><DIS:<MMS2:4N,5N><ELSE><MMW2:1N,2N><ENDIF><ENDREP>

 

You still haven't included the missing mouse position increment commands I pointed out!

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

You still haven't included the missing mouse position increment commands I pointed out!

 

--

Terry, East Grinstead, UK

 

 

Wow, calm down. I'm completely new at this. I tried one thing that didn't really do me any favors. Couldn't find anything that was %N1%(x) + 1.

 

Thanks

Link to comment
Share on other sites

Wow, calm down. I'm completely new at this. I tried one thing that didn't really do me any favors. Couldn't find anything that was %N1%(x) + 1.

 

Thanks

 

OK, here's an example we can all access, to illustrate the principles.

// This macro will move the mouse cursor rightwards in ME 3 Script Editor.

// Displaying a message after every single pixel move could be very slow, so this will not be done.

// Instead, when it reaches the non-whilte area marking the RH border it will display a message.

// (This is obviously a rather silly example, as the non-white location will be at a fixed X coordinate anyway, so hardly needs much finding, but hopefully it illustrates the principle using a window we can all access.)

// Then it will move down a 'row' and repeat the process.

// In MY case, with a screen resolution of 1920 x 1200, this move down is 18 pixels (calculated to move to each gap between commands).

// But that may differ for other users.

// ================================================================

// First, ensure that the focus is on the Scripting Editor window, to allow flexible activation.

Activate Window: "Macro Express - Scripting Editor - [Macro Name: TEMP Example for fug5333]"

// Move the mouse cursor to a specific position inside Script Editor, in the Macro Script' area.

// This should be in a white area, above the command text, so that there is uninterrupted white spaceto the right.

Mouse Move Window 426, 215

// Make a note of the position so that (in a more realistic macro) you can return to them, or to at least the X coordinate.

Get Mouse Position Window: %N1%, %N2%

// Start a loop that will be repeated indefinitely, relying on other logic to stop it.

Repeat Until %T1% <> %T1%

Get Pixel: Under Mouse into %N3%

// Check if the mouse is over a white pixel

If Variable %N3% = 16777215

// If it is, move the cursor 1 pixel to the right and then continue after the End If command.

Mouse Move Position 1, 0

Else

// If it is NOT white then do the following commands.

Text Box Display: Border message

// Change the Y coordinate so that you can move to the next row

Variable Modify Integer: %N2% = %N2% + 18

Mouse Move Window 413, %N2%

End If

Repeat End

 

And here is the code, for pasting into the Direct Editor:

 

<REM2:This macro will move the mouse cursor rightwards in ME 3 Script Editor.><REM2:Displaying a message after every single pixel move could be very slow, so this will not be done.><REM2:Instead, when it reaches the non-whilte area marking the RH border it will display a message.><REM2:(This is obviously a rather silly example, as the non-white location will be at a fixed Y coordinate anyway, so hardly needs much finding, but hopefully it illustrates the principle using a window we can all access.)><REM2:Then it will move down a 'row' and repeat the process.><REM2:In MY case, with a screen resolution of 1920 x 1200, this move down is 18 pixels (calculated to move to within the next command).><REM2:But that may differ for other users.><REM2:================================================================><REM2:First, ensure that the focus is on the Scripting Editor window, to allow flexible activation.><ACTIVATE2:Macro Express - Scripting Editor - [Macro Name: TEMP Example for fug5333]><REM2:Move the mouse cursor to a specific position inside Script Editor, in the Macro Script' area.><REM2:This should be in a white area, above the command text, so that there is uninterrupted white spaceto the right.><MMW2:426,215><REM2:Make a note of the position so that (in a more realistic macro) you can return to them, or to at least the X coordinate.><MOUSEPOS:F:01:02><REM2:Start a loop that will be repeated indefinitely, relying on other logic to stop it.><REP3:08:000002:000001:0001:1:01:T1><GETPXM:3><REM2:Check if the mouse is over a white pixel><IFVAR2:2:03:1:16777215><REM2:If it is, move the cursor 1 pixel to the right and then continue after the End If command.><MMP2:1,0><ELSE><REM2:If it is NOT white then do the following commands.><TBOX4:T:1:000821Center000450000200:000:Border messageThe macro has reached a non-white pixel.

 

After you close this message, it will continue by going down a row and repeating the process.

 

You must stop the macro MANUALLY when you've seen enough.><REM2:Change the Y coordinate so that you can move to the next row><NMVAR:01:02:1:0000002:2:0000018><MMW2:413,2N><ENDIF><ENDREP>

 

I recommend you study that and adapt it to your own requirement. Post back if you still have problems.

 

--

Terry, East Grinstead, UK

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

×
×
  • Create New...