relative coordinates
Moderators: Dorian (MJT support), JRL
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
relative coordinates
Why doesn't the software have relative commands.
This makes no sense to me.
Example : if you are going to take a screen shot of a window.
Why isn't there a command that permits you to specify the window and coordinates relative to that window ?
(Or am I misinterpreting the help section on commands ?)
Isn't the whole idea supposed to be automation ?
This makes no sense to me.
Example : if you are going to take a screen shot of a window.
Why isn't there a command that permits you to specify the window and coordinates relative to that window ?
(Or am I misinterpreting the help section on commands ?)
Isn't the whole idea supposed to be automation ?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
It *does*. For a start there's the MouseMoveRel command to move to a position relative to the active window. We actually advise not to use mouse events and if at all possible avoid screen coordinates altogether. The screen image recognition functions are so fast they can operate on the entire screen almost instantaneously so you don't need to care where an object is. Just tell Macro Scheduler to find it and then the script has the coordinates of wherever it happened to be at the time. You can't get much more relative than that - screen objects can move all over the place - Macro Scheduler will still find them.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
What I am talking about is taking the screen capture.
Say for example it is neccessary to do an ocr on a portion of the window to get text each time you open an application.
Also it can become neccessary to specify coordinates for image recognition if more than one area needs to be searched .
In other words lets say this graphic can exist in more than one region and you need to check each.
Say for example it is neccessary to do an ocr on a portion of the window to get text each time you open an application.
Also it can become neccessary to specify coordinates for image recognition if more than one area needs to be searched .
In other words lets say this graphic can exist in more than one region and you need to check each.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
A sample of Marcus' explanation.
Code: Select all
//Open notepad to have a sample window to work with
Run>notepad.exe
WaitWindowOpen>notepad*
Wait>1
GetWindowHandle>notepad*,hndwin
//Create a file of the window and put the window image to the clipboard.
SetFocus>notepad*
GetActiveWindow>title,WinX,WinY,WinW,WinH
Add>winw,%winx%
Add>winh,%winy%
ScreenCapture>WinX,WinY,WinW,WinH,%temp_dir%%title%-screen shot.bmp
Last edited by JRL on Fri Feb 22, 2008 11:44 pm, edited 1 time in total.
Good example JRL and good observation Me_again. Here's one more consideration to "throw onto the pile". The screen resolution of the PC that is running the macro can change. For instance, lets say you get a macro that looks for matches within screenshot images... working with the PC screen res set to 1024x768. Then for some reason, you or someone else changes the res to 800x600....Me_again wrote:Or start by maximizing the window using WindowAction>, or MoveWindow> and ResizeWindow>, 'cause if the position of the window on the screen can be variable, maybe so can the size, so maybe those multiple areas you want to search aren't all visible and you won't have a reliable routine.
...things aren't going to work anymore but you can allow for this. When the macro runs, you can test to see what current screen res is and if its not the target res the macro was designed to work with, you can alert the user and abort.
Or if you want to have it work at two popular resolutions, you can "build it twice", have two sections of code, one that can cope with one res and one the other... I had to do that once, couldn't guarantee what the clients would set their screen res to because as folks get older and their sight degrades, they tend to like larger text and if they can change it... they will.
Take care
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
Yes I'm just figuring it to be more convenient if it was built in.mtettmar wrote:Focus the window with SetFocus then use GetActiveWindow to get the coordinates and size of the window. So now you have coordinates of the window on the screen and can capture just that portion (I.e. Capture just that window). So now you can work relative to that window.
Relative coordinates would seem to be a common usage function.
As far as finding images I wasnt aware that this version finds mutiple locations.
I had just downloded it and hadn't seen that feature.
It's very impressive.
Well thought out.
But even with that command relative coordinates eliminate the need to calculate coordinates from the window's location.
In conjuction with a menu tool that shows relative coordinates this could be a real time saver in writing code and the code would be more condensed.
The objective of this program after all is providing commands from rapid coding.
Last edited by SuitedAces on Sun Feb 24, 2008 3:29 am, edited 3 times in total.
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
I'm envisioning one command with relative coordinates and window size as arguments.Me_again wrote:Or start by maximizing the window using WindowAction>, or MoveWindow> and ResizeWindow>, 'cause if the position of the window on the screen can be variable, maybe so can the size, so maybe those multiple areas you want to search aren't all visible and you won't have a reliable routine.
In fact let's say you are looking for an image and it can occur in multiple locations.
You are then forced to write code that calculates the location of each of these images relative to the window, even if you decide to preposition the window.
Why not instead have a tool that reads the mouse coordinates relative to the chosen window and then simply enter those coordinates in your command or code in one step.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
If you go into macro properties you will see the mouse cursor reported at top right. Click on the drop down and select "Relative" and it now shows coordinates relative to the active window. This is also available in the script editor.
If you capture a window to a bitmap and then use findimagepos you are working relatively to that window. All you have to do to turn back into absolute screen coordinates is add the top left coordinates of the window to the result. Just one line of code.
If you capture a window to a bitmap and then use findimagepos you are working relatively to that window. All you have to do to turn back into absolute screen coordinates is add the top left coordinates of the window to the result. Just one line of code.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
One line of code ?
How so?
Let's take a relative command MoveMouseRel (wnd,x,y)
that is one line of code.
Presently we have MoveMouse(x,y)
Can you show me how to get from MoveMouse to the equivalent of MoveMouseRel in one additional line of code ?
I know that this sounds to some like nitpicking, and relative commands do not achieve anything epic but the entire concept of a product like this is rapid development.
I just do not see anything redeeming about the ritual adding lines of code for coordinates regardless of how simplistic it is.
How so?
Let's take a relative command MoveMouseRel (wnd,x,y)
that is one line of code.
Presently we have MoveMouse(x,y)
Can you show me how to get from MoveMouse to the equivalent of MoveMouseRel in one additional line of code ?
I know that this sounds to some like nitpicking, and relative commands do not achieve anything epic but the entire concept of a product like this is rapid development.
I just do not see anything redeeming about the ritual adding lines of code for coordinates regardless of how simplistic it is.
Last edited by SuitedAces on Fri Feb 29, 2008 2:13 pm, edited 1 time in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Like this:
MouseMoveRel>20,20
That moves the mouse to position 20,20 *relative* to the upper left position of the window.
E.g. let's say the window happens to start at position 500,500. MouseMoveRel>20,20 would move the mouse to screen position 520,520.
If you go into the editor you can see the mouse position at top right. Click the drop down arrow to select relative. It will now show you the mouse position relative to whatever window you are over. So now you can determine what X,Y values to use in the MouseMoveRel command.
MouseMoveRel>20,20
That moves the mouse to position 20,20 *relative* to the upper left position of the window.
E.g. let's say the window happens to start at position 500,500. MouseMoveRel>20,20 would move the mouse to screen position 520,520.
If you go into the editor you can see the mouse position at top right. Click the drop down arrow to select relative. It will now show you the mouse position relative to whatever window you are over. So now you can determine what X,Y values to use in the MouseMoveRel command.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Ok, maybe I'm missing something. Feel free to describe what new command you would like to see. Quite open to suggestions and adding new commands - that's how Macro Scheduler has got where it is today.
Your original post was about the ScreenCapture command. At present ScreenCapture accepts a rectangle. That rectangle could be the entire screen or a portion of or a rectangle covering a window.
If we want to capture just one window we would do:
SetFocus>window_name,
GetActiveWindow>window,X,Y,w,h
ScreenCapture>X,Y,{%X%+%w%},{%Y%+%h%},filename
If we wanted to capture the entire screen we could do:
GetScreenRes>w,h
ScreenCapture>0,0,w,h,filename
So there's only one extra line of code between the two.
Perhaps you are suggesting commands like:
ScreenCaptureEntireScreen>filename
and:
ScreenCaptureJustWindow>window_title,filename
Although they only remove 1-2 lines of code, they are certainly nice and simple.
Your original post was about the ScreenCapture command. At present ScreenCapture accepts a rectangle. That rectangle could be the entire screen or a portion of or a rectangle covering a window.
If we want to capture just one window we would do:
SetFocus>window_name,
GetActiveWindow>window,X,Y,w,h
ScreenCapture>X,Y,{%X%+%w%},{%Y%+%h%},filename
If we wanted to capture the entire screen we could do:
GetScreenRes>w,h
ScreenCapture>0,0,w,h,filename
So there's only one extra line of code between the two.
Perhaps you are suggesting commands like:
ScreenCaptureEntireScreen>filename
and:
ScreenCaptureJustWindow>window_title,filename
Although they only remove 1-2 lines of code, they are certainly nice and simple.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 50
- Joined: Thu Feb 21, 2008 9:11 pm
I appreciate your willingness to consider suggestions.
Here is what came to my mind as a useful command
ScreenCaptureRel>wnd,h,w,x1,y1,x2,y2,filename,ReturnVal
Giving you the ability to capture a portion of a window.
The height & width of the window would be set with the command.
Because if you have a sizable window you want to ensure that your capture is going to be as intended.
The ReturnVal is a true or false , indicating if the window was found.
So that the command also gives focus to the window and if not found returns a False.
It might also be neccessary to include top,left arguments for the window to make certain that the region being captured isn't off screen.
ScreenCaptureRel>wnd,L,T,h,w,x1,y1,x2,y2,filename,ReturnVal
Or instead of a ReturnVal a built in error message like some of the other commands generate.
Here is what came to my mind as a useful command
ScreenCaptureRel>wnd,h,w,x1,y1,x2,y2,filename,ReturnVal
Giving you the ability to capture a portion of a window.
The height & width of the window would be set with the command.
Because if you have a sizable window you want to ensure that your capture is going to be as intended.
The ReturnVal is a true or false , indicating if the window was found.
So that the command also gives focus to the window and if not found returns a False.
It might also be neccessary to include top,left arguments for the window to make certain that the region being captured isn't off screen.
ScreenCaptureRel>wnd,L,T,h,w,x1,y1,x2,y2,filename,ReturnVal
Or instead of a ReturnVal a built in error message like some of the other commands generate.