Mouse follows focus in Windows, an AutoHotkey script

If you are unlucky enough to have to use Windows, but lucky enough to get AutoHotkey installed, then here is a script that I use to enable the mouse-follows-focus function which I find indispensable. Somewhere deep in the settings, Windows has focus-follows-mouse, i.e. focus (and raise) the window where the mouse pointer currently is, which is good if you find the mouse the quickest way to switch between windows. But apparently the only way in Windows to get mouse-follows-focus, i.e. automatically bring the mouse pointer to the window that you switched to by keyboard, is an AutoHotkey script.


~!Tab::
KeyWait, Alt
KeyWait, Tab
WinGetPos, X, Y, width, height, A
MouseMove,10,10,
return

#c::
WinGetPos, X, Y, width, height, A
MouseMove,10,10,
return

The idea in this AutoHotkey script is to bring the mouse pointer to the top left corner of the focused window when switching windows by Alt+Tab. It does not always work, so there is also Win+c.

3 Replies to “Mouse follows focus in Windows, an AutoHotkey script”

  1. Meanwhile Autohotkey script language has had an incompatible update and this code no longer works with Autohotkey version 2 (and above, if there be more updates).

Leave a Reply

Your email address will not be published. Required fields are marked *