Is there a way to make the mouse pointer disappear when the computer goes idle? If the solution could work in both Windows XP and Windows 7, that would be great.
4 Answers
Based on what I found here, I was able to make the following AutoHotkey code:
SystemCursor("Init")
SetTimer, CheckIdle, 250
return
CheckIdle:
TimeIdle := A_TimeIdlePhysical // 1000
if TimeIdle >= 3
{
SystemCursor("Off")
}
else
{
SystemCursor("On")
}
return
#Persistent
OnExit, ShowCursor ; Ensure the cursor is made visible when the script exits.
return
ShowCursor:
SystemCursor("On")
ExitApp
SystemCursor(OnOff=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ; blank cursors
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13 ; handles of default cursors
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ = h ; active default cursors
VarSetCapacity( h_cursor,4444, 1 )
VarSetCapacity( AndMask, 32*4, 0xFF )
VarSetCapacity( XorMask, 32*4, 0 )
system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
StringSplit c, system_cursors, `,
Loop %c0%
{
h_cursor := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
h%A_Index% := DllCall( "CopyImage", "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
, "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ = b ; use blank cursors
else
$ = h ; use the saved cursors
Loop %c0%
{
h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
}
}
Try this: Cursor Hider
-
1This is what I'm looking for, but $20 seems like a bit much.– JosephCommented Oct 29, 2009 at 9:15
If you don't mind that little coding will be probably necessary, you can use AutoHotkey. See this forum post for more info on what you want to achieve.
-
The post you linked to only makes the mouse invisible in the AutoHotkey application created. You got me on the right track though, so I'll give you an upvote. Thanks.– JosephCommented Nov 10, 2009 at 3:08
8 years on and Joseph's answer is still good and works in AHK! BUT I have made it even better.. in my opinion of cause.
I have added a mouse check so the cursor only shows again when it is moved. True that I could have added other mouse events like clicks but since the cursor is hidden I think it too edge case to bother. You are free to add it yourself if you want it :)
What I changed was move #Persistent
to the top as it is global and present for the entire script no matter it is.
Added CoordMode, Mouse, Screen
and MouseGetPos, ix, iy
in autoexec section and MouseGetPos, ix, iy
again when going to idle. MouseGetPos, cx, cy
gets set on every CheckIdle
and the variables are compared on mouse movement with if (cx != ix or cy != iy)
.
#Persistent
CoordMode, Mouse, Screen
MouseGetPos, ix, iy
SystemCursor("Init")
SetTimer, CheckIdle, 250
return
CheckIdle:
MouseGetPos, cx, cy
TimeIdle := A_TimeIdlePhysical // 1000
if (TimeIdle >= 3)
{
MouseGetPos, ix, iy
SystemCursor("Off")
}
else if (cx != ix or cy != iy)
{
SystemCursor("On")
}
return
OnExit, ShowCursor ; Ensure the cursor is made visible when the script exits.
return
ShowCursor:
SystemCursor("On")
ExitApp
SystemCursor(OnOff=1) ; INIT = "I","Init"; OFF = 0,"Off"; TOGGLE = -1,"T","Toggle"; ON = others
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 ; system cursors
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13 ; blank cursors
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13 ; handles of default cursors
if (OnOff = "Init" or OnOff = "I" or $ = "") ; init when requested or at first call
{
$ = h ; active default cursors
VarSetCapacity( h_cursor,4444, 1 )
VarSetCapacity( AndMask, 32*4, 0xFF )
VarSetCapacity( XorMask, 32*4, 0 )
system_cursors = 32512,32513,32514,32515,32516,32642,32643,32644,32645,32646,32648,32649,32650
StringSplit c, system_cursors, `,
Loop %c0%
{
h_cursor := DllCall( "LoadCursor", "uint",0, "uint",c%A_Index% )
h%A_Index% := DllCall( "CopyImage", "uint",h_cursor, "uint",2, "int",0, "int",0, "uint",0 )
b%A_Index% := DllCall("CreateCursor","uint",0, "int",0, "int",0
, "int",32, "int",32, "uint",&AndMask, "uint",&XorMask )
}
}
if (OnOff = 0 or OnOff = "Off" or $ = "h" and (OnOff < 0 or OnOff = "Toggle" or OnOff = "T"))
$ = b ; use blank cursors
else
$ = h ; use the saved cursors
Loop %c0%
{
h_cursor := DllCall( "CopyImage", "uint",%$%%A_Index%, "uint",2, "int",0, "int",0, "uint",0 )
DllCall( "SetSystemCursor", "uint",h_cursor, "uint",c%A_Index% )
}
}