WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Mouse and Cursor Topics

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

MouseMove Coordinates Explained

 Keywords:  MouseMove Coordinates Virtual Relative X Y Parent Window

Question:

I found a tech article w15550 that states the MouseMove and MousePlay functions use absolute coordinates. Yet the documentation for MouseMove states: All coordinates are based on a virtual 1000 x 1000 screen. and the documentation for MousePlay states: space-delimited string with the final mouse x and y position, in virtual 1000x1000 units.

Based on my tests MouseMove is using the virtual 1000x1000 screen.

MouseMove also seems to have a problem working relative to the specified Parent window. For Example:

 
; Windows 7
; I would expect this to place the mouse in the center of the Sound window because I specified a Parent window name
; However, It seems to place the mouse in the middle of the desktop
; Documentation states: If "parent-windowname" specifies a top-level window and "child-windowname" is a blank string, the specified X-Y coordinates are relative to "parent-windowname".
 
parent = 'Sound'
Run( 'control', 'mmsys.cpl' )
WinWaitExist( parent, 5)
 
X_pos=500
Y_pos=500
 
MouseMove(X_pos, Y_pos, parent, '')
 
result = MouseInfo( 0 )
if result != parent  
   BoxOpen('','Houston we have a problem')
   TimeDelay(3)
endif
exit
MouseMove seems to be ignoring the parent window name.

Answer:

That script works as expected. I think you are confusing a few WinBatch speak terms so lets get that straitened out.

First I think you are confusing the term virtual with the term relative. In WinBatch speak a virtual coordinate is not the same thing as a relative coordinate. In fact, virtual coordinates are absolute with regard to MouseMove or MousePlay in that each virtual coordinate will always represent the same number of device coordinates as long as the total number of device coordinates stays the same. So virtual coordinates will always have the same size on all screens with the same display resolution.

Next let us take a look at what 'relative to a window' does and does not mean in WinBatch speak.

'Relative to a window' does not mean:
That virtual coordinate size is change so that all virtual coordinates all fit in the window's rectangle and the mouse is only moved within the window's rectangle. Remember we just established that virtual coordinates are absolute so they don't change unless the device resolution changes.

'Relative to a window' does mean:
That the mouse is moved relative to the origin of the window's rectangle instead of relative to the display's origin. Basically, the mouse coordinates are offset by the difference between the display's upper-left corner and the window's upper-left corner. Using your script the mouse cursor ends up a bit to the right and below the center of the display on my system because the targeted window is displayed with its rectangle origin a bit below and to the right of the display's upper-left hand corner. I


Article ID:   W17988
Filename:   MouseMove Coordinates Explained.txt
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38