Mick Posted March 7, 2021 Report Share Posted March 7, 2021 Is it possible to use the mouse locator in a macro? I would like to get the x, y and size of a rectangle the user draws on screen. Also be able to modify the location and size of rectangle, just like the mouse locator. Quote Link to comment Share on other sites More sharing options...
acantor Posted March 7, 2021 Report Share Posted March 7, 2021 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. Quote Link to comment Share on other sites More sharing options...
rberq Posted March 7, 2021 Report Share Posted March 7, 2021 Get Mouse Position into (x_coordinate, y_coordinate) Relative to Screen Quote Link to comment Share on other sites More sharing options...
Cory Posted March 7, 2021 Report Share Posted March 7, 2021 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted March 8, 2021 Report Share Posted March 8, 2021 After reading the three very different responses to your question, there's one thing that is very clear: We all have different ideas of what you're trying to achieve! Could you provide more details? Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 8, 2021 Report Share Posted March 8, 2021 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 Quote Link to comment Share on other sites More sharing options...
Mick Posted March 9, 2021 Author Report Share Posted March 9, 2021 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. Quote Link to comment Share on other sites More sharing options...
terrypin Posted March 9, 2021 Report Share Posted March 9, 2021 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. 🙂 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.