tatagi wrote: ↑26 Sep 2020, 22:34
would you please tell me what the difference is from w0z's and why it looks a bit complicated?
Although in its principle highly correct,
w0z's sample code suffers from an obvious lack: it blindly loops, indiscriminately and continuously. As for a WinEventHook, it allows you to intercept application events (here the
EVENT_OBJECT_LOCATIONCHANGE one, generated when
'An object has changed location, shape, or size.') and implement a custom handling of them before giving control back to the application. Moreover, the hooking is here design in such way that if receives events only from the process to which belong the application (in the example: notepad) and really handle the event if the object associated with the event is the mouse pointer (
OBJID_CURSOR). In other words, it actually does ahk checking and processing only when the cursor moves (and while hovering notepad).
Btw, one other option, taking the most of built-in common ahk commands is probably to use in synergy the three following commmands:
timers,
winwait and
winwaitnotactive.
It looks more complicated because ahk does not provide a built-in command to set a wineventhook. On the contrary, it provides handy and easy-to-use commands to retrieve the current position of the mouse cursor and move it (
i.e. MouseGetPos and
MouseMove) - but there's no implication that in the background these latter commands do not unfolds against, implies as much coding efforts.
A_AhkUser