views:

197

answers:

3

I'm running the below code and I expect the mouse to move to the center of the currently active window when I hit comma.....instead it is moving to different points on the screen, depending on where the window is on the screen. It only centers the mouse properly when the window is positioned at the top left (x=0, y=0).

#NoEnv
SendMode Input
#WinActivateForce

Sysget, Mon2, Monitor, 2

,::

WinGetActiveStats, Title, Width, Height, X, Y
 {
MsgBox, The active window "%Title%" is %Width% wide`, %Height% tall`, and positioned at %X%`,%Y%.

;center_x:=X+(Width*.5)
;center_y:=Y+(Height*.5)

MouseMove, X+(Width*.5), Y+(Height*.5), 90

 }
Return
A: 

I would be sure that Width and Height are the actual dimensions of the window and not the screen resolution. Then check X and Y to ensure they're the actual top-left corner of the active window.

If the width and height are not from the actual window, i.e. the screen size, then this is expected behaivor. Perhaps you could show us the calling function to get a better idea of where those parameters are coming from.

Trey Sargent
Trey, Per the following link, all variables I used should correspond to active window position/dimensions. http://autohotkey.free.fr/docs/commands/WinGetActiveStats.htmThe MsgBox shows that these are being read correctly, but the Mousemove is still not moving the mouse to the proper position.
A: 

Per the following link, all variables (width, height, x, y) should correspond to the active window.

http://autohotkey.free.fr/docs/commands/WinGetActiveStats.htm

To test this I used the MsgBox and all variables appear to be correct, but when I execute, the mouse still goes to the wrong position, assuming that the active window is not at position 0,0 on my monitor.

A: 

the problem was that MousMove uses the coordinates of the window by default, so I changed the MouseMove line to the following:

MouseMove, Width*.5, Height*.5

All is good.