Thursday, November 20, 2008

AHK - Auto Cursor Hider

This script automatically hides the mouse cursor after a 1 second delay, then makes it visible again when you start moving it.

#Persistent
#NoTrayIcon
OnExit, ShowCursor
SetTimer, CheckMouse, 10
Cursor := 1
return

CheckMouse:
MouseGetPos, MX, MY
If (MX != _MX || MY != _MY) {
SystemCursor(1)
LastMove := A_TickCount
Cursor := 1
_MX := MX
_MY := MY
}
If (Cursor && (A_TickCount - LastMove) > 1000) {
SystemCursor(0)
Cursor := 0
}
Return

ShowCursor:
SystemCursor("On")
ExitApp

SystemCursor(T=1)
{
static AndMask, XorMask, $, h_cursor
,c0,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13
, b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13
, h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13
if (T = "Init" or T = "I" or $ = "")
{
$ = h
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 )
}
}
$ := T=0 ? "b" : "h"

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% )
}
}


* Note - This script uses Laszlo's SystemCursor() function, found here

Lazlo's SystemCursor() function

No comments: