I’m trying to develop an application that, when running, will hide the mouse cursor wherever it happens to be on the screen after 5 seconds of inactivity, even if my app isn’t in the foreground. Then, once the mouse moves again, the mouse should reappear instantly.
I’ve been reading a lot about low-level mouse hooks, but can’t seem to wrap my head around the delegates and callbacks that, to me, make the code a lot harder to read.
Here are some of the things I’ve been looking at in terms of solutions:
Hide mouse cursor after an idle time
http://blogs.msdn.com/b/toub/archive/2006/05/03/589468.aspx
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
And I seemed to get closest with this one:
http://weblogs.asp.net/jdanforth/archive/2011/03/19/detecting-idle-time-with-global-mouse-and-keyboard-hooks-in-wpf.aspx
My problem seems to be that if I set up a timer on my main form for 5 seconds, then yes the mouse disappears after those 5 seconds if it’s inactive, but then it also takes 5 seconds for the mouse to reappear! Would the solution simply be to have two separate timers and separate events?
Thanks so much for the help!
You dont have to create 2 different timers. I would use the same timer, but have a private member variable that keeps track of whether the cursor is hidden. Once you hide it, you can reset the timer to be a lot shorter (say 500 ms) and continue to track it to turn it back on.
You can try this: