Jump to content
Macro Express Forums

Programmatically use Mouse Locator


Recommended Posts

I don't think you can directly obtain information about a rectangle on the screen.

 

However, it might be possible to calculate the position of a rectangle of a known colour.

 

If I were to take on a project like this, I would try to simplify the problem by, for example, making the rectangle one colour, assuming the mouse pointer is manually placed inside the rectangle, and working out the dimensions of the rectangle, not its position.

 

The logic might look something like this:

 

Assume the rectangle is a solid colour, 123456.

Assume the mouse pointer is somewhere inside the rectangle.

 

Get Mouse Cursor Position [StartX, StartY]

 

Count = 0

Repeat Until Pixel Colour is NOT 123456

Get Pixel Colour

Move Mouse Cursor UP one pixel

Count = Count + 1

End Repeat

Top y coordinate is Count

 

Move Mouse Cursor to [StartX, StartY]

 

Count = 0

Repeat Until Pixel Colour is NOT 123456

Get Pixel Colour

Move Mouse Cursor DOWN one pixel

Count = Count + 1

End Repeat

Bottom y coordinate is Count

 

Repeat twice: to work out left x coordinate and right x coordinate.


Here's another way that might also work, by finding and tracing the perimeter of a rectangle.

 

Repeatedly move UP up by 1 pixel until the colour is not 123456

Move down one pixel.

Repeatedly move RIGHT by 1 pixel until the colour is not 123456

Move left one pixel.

Repeatedly move DOWN by 1 pixel until the colour is not 123456

Move up one pixel.

Repeatedly move LEFT by 1 pixel until the colour is not 123456

 

This could be a fun project to take on to sharpen one's Macro Express skills. The script will likely be computationally intense, and might run slowly! Aiming for an approximate answer by checking every 5 or 10 or 100 pixels could save a lot of time.

 

Link to comment
Share on other sites

Your user would not be able to draw a rectangle on the screen. You could start a macro and get the coordinates. Then pause the macro and prompt them to move to anther location and hit Enter to close the MessageBox and read in the next coordinates. 

Link to comment
Share on other sites

I wrote a macro years ago that has proved very useful. On activation with its hot key it asks me to click two positions on the screen. Then it tells me the width and height of the rectangle. Usually it’s just the horizontal or vertical difference between those clicked positions that I’m seeking. The macro uses the same simple command as the example offered by @rberq.

 

Like others I’m unclear about your exact objective, but let me know if you want my macro’s code.

 

Terry

 

Link to comment
Share on other sites

Okay, I made a mistake and had 2 programs mixed up.

What I was attempting to do was automate the screen snipping tool to be able to repeat the same snipping area over and over.

I found a better tool, it's called Movavi - Screen Capture.

I automated this with ME so the F8 key captures an area of the screen and saves it to a file.

In Movavi you can set the area of the screen you want to capture.

Thanks for all the help.

Link to comment
Share on other sites

Pleased to hear you got it sorted, and thanks for the feedback.

 

I do exactly the same thing with Snagit.

 

I’m sure it could be also be done with an MX Pro macro, but if there’s another tool at hand that does it more quickly and reliably then it’s no contest. 🙂

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