Windows contains settings to hide mouse pointer while typing, but doesn't contains a settings to move pointer to active typing area. I mean I can switch typing areas by tab, or enter, or alt+tab, etc. but my pointer is still far away. What I should use (program, script, autohotkey script) to make similar system-wide behavior?


AutoHotkey will let you assign a shortcut key to move the mouse to the current cursor location if that's what you're after.

#a::                             ; shortcut key is <Win>+a
    CoordMode, Caret, Screen     ; set Caret to use Screen Coordinates
    CoordMode, Mouse, Screen     ; set Mouse to use Screen Coordinates
    MouseMove, %A_CaretX%, %A_CaretY%   ; move mouse to caret position

You could also assign the script to run after certain events where you know the cursor focus will change

~!Tab Up::
    keywait, Alt ; wait for user to let off alt key after activation
    sleep 200    ; give the selected program time to activate
    gosub #a     ; move the mouse
| improve this answer | |
  • it doesn't work in visual studio, sublime text. Do you have any ideas how is we can adapt it to deal with that? – Georgy Grigoryev Feb 11 '16 at 12:36

To do this, you need to use a DllCall to get the true caret position. The following works for me everywhere I tested it (including MS Word, which doesn't work with A_CaretX/Y).

#s:: ;assign hotkey to win + s
; https://msdn.microsoft.com/en-us/library/windows/desktop/ms632604(v=vs.85).aspx
VarSetCapacity(GuiThreadInfo, 48) ;create "struct"
NumPut(48, GuiThreadInfo,,"UInt") ;update cbSize member

; https://msdn.microsoft.com/en-us/library/windows/desktop/ms633506(v=vs.85).aspx
DllCall("GetGUIThreadInfo", int, 0, ptr, &GuiThreadInfo)

hwnd := NumGet(&GuiThreadInfo+7*4) ;get 7th member of struct
left := NumGet(&GuiThreadInfo+8*4) ;8th member
top  := NumGet(&GuiThreadInfo+9*4) ;9th

ControlGetPos, x, y,,,,ahk_id %hwnd% ;get position of active control, relative to window
MouseMove, left+x, top+y
| improve this answer | |
  • Doesn't work at win10 – Georgy Grigoryev Mar 5 '16 at 14:17
  • @GeorgyGrigoryev It does here! Are you running 64 bit or 32 bit? Which programs did you try it with specifically? Did you get any errors? What happens when you press Win + S with this script? What version of AHK did you use to run it? – SleepingInsomniac Mar 5 '16 at 20:31
  • Hmm, I tried it with some different programs - turns out it works the same places A_CaretX/Y does, I thought they didn't work with MS Word which is where I tested this script...back to the drawing board! – SleepingInsomniac Mar 5 '16 at 20:51
  • Yes, correct, same behavior as CarretX/Y and I stopped at this solution. – Georgy Grigoryev Sep 25 '16 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.