Unwanted Rodent

Published: Wed 02 August 2017

In Blog.

I’m not your typical Windows user. I spend most of my time inside zsh, inside tmux, inside Windows Subsystem for Linux. My hands have a little bit of hermit in them, and prefer to stay home, only venturing out to my also-quite-sedentary pointing device of choice when absolutely necessary.

As such, I frequently get driven up the wall by my mouse pointer being “in the way”. I haven’t quite figured out precisely what isn’t working as it should, but everything I read says that the mouse cursor will automatically hide itself if the mouse isn’t used (this is typically useful when capturing content via the keyboard in a program like Microsoft Word). Perhaps the fact that I happen to be typing in a non-mainstream program like bash or zsh means that that doesn’t apply.

In any case, AutoHotkey to the rescue (once again); it is really easy to call Windows API functions from ahk, as it turns out. I normally brace myself when I finally get to the point of wanting to do something using ahk because the language really is awful and wholly unintuitive. Never-the-less, biting my lip I plunged in, and was pleasantly surprised:

The trick is not to try to make the mouse cursor hide (since doing is window-specific and not global), but to “move it” somewhere out of the way (I like the top left corner of the screen).

In ahk lingo:

; Make cursor go to (0,0)
DllCall("SetCursorPos", "Int", 0, "Int", 0)

This causes the hot-key Ctrl-Backspace to call the SetCursorPos API (User32.dll) with a coordinate of (0,0). Every now-and-again, time spent on something turns out to be worth it; this is such a time.

Comments !