foo
foo

Reputation: 406

AutoHotKey: Active Window then MouseMove

I want to active certain window and then move the mouse to a position relative to the active window's client area. See the code below:

CoordMode, Mouse, Client
WinActivate, titile
MouseMove, 200, 100

The window is actived while the mouse seems not move. But if I change the code order, like:

CoordMode, Mouse, Client
MouseMove, 200, 100    
WinActivate, titile

The window is actived as expect, while the mouse moves, but relative to the last window. I could not figure it out.

Upvotes: 1

Views: 2854

Answers (2)

johnlee
johnlee

Reputation: 392

  1. WinActivate does not update the Last Found window.

  2. You don't need to wait until the window activates to move the mouse pointer.

Try:

; Its location doesn't matter so long as it comes before mouse movements.
CoordMode Mouse, Client

; WinExist ensures the Last Found window is updated.
WinActivate % "ahk_id " WinExist("titile")

; Better than MouseMove in a number of aspects.
SendInput {Click 200 100 0}

Upvotes: 1

576i
576i

Reputation: 8362

After performing,

WinActivate, titile

try

WinWaitActivate, titile

so that your code stops until the window is activated

Also try to move

CoordMode, Mouse, Client

behind the WinWaitActivate command

Depending on your windows/autohotkey version, replace Client with Relative

Upvotes: 1

Related Questions