Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- /*
- Auto Hide Mouse Cursor
- - Hides mouse cursor after 2 seconds of inactivity
- - Shows cursor immediately on mouse movement
- */
- ; Constants for cursor types
- class CURSOR_ID {
- static ARROW := 32512
- static IBEAM := 32513
- static WAIT := 32514
- static CROSS := 32515
- static UPARROW := 32516
- static SIZENWSE := 32642
- static SIZENESW := 32643
- static SIZEWE := 32644
- static SIZENS := 32645
- static SIZEALL := 32646
- static NO := 32648
- static HAND := 32649
- static APPSTARTING := 32650
- static HELP := 32651
- }
- class CursorManager {
- static __New() {
- ; Initialize position variables
- MouseGetPos(&x, &y)
- this.lastX := x
- this.lastY := y
- this.isHidden := false
- this.blankCursor := this.CreateBlankCursor()
- ; Set timers for movement check and auto-hide
- SetTimer(this.CheckMouseMove.Bind(this), 100)
- SetTimer(this.CheckIdleTime.Bind(this), 2000)
- }
- static CreateBlankCursor() {
- return DllCall("CreateCursor", "Uint", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32
- , "Ptr", Buffer(32*4, 0xFF), "Ptr", Buffer(32*4, 0))
- }
- static CheckMouseMove() {
- MouseGetPos(¤tX, ¤tY)
- if (currentX != this.lastX || currentY != this.lastY) {
- if (this.isHidden)
- this.ShowCursor()
- this.lastX := currentX
- this.lastY := currentY
- }
- }
- static CheckIdleTime() {
- MouseGetPos(¤tX, ¤tY)
- if (currentX == this.lastX && currentY == this.lastY && !this.isHidden)
- this.HideCursor()
- }
- static HideCursor() {
- static cursors := [
- CURSOR_ID.ARROW, CURSOR_ID.IBEAM, CURSOR_ID.WAIT, CURSOR_ID.CROSS,
- CURSOR_ID.UPARROW, CURSOR_ID.SIZENWSE, CURSOR_ID.SIZENESW,
- CURSOR_ID.SIZEWE, CURSOR_ID.SIZENS, CURSOR_ID.SIZEALL,
- CURSOR_ID.NO, CURSOR_ID.HAND, CURSOR_ID.APPSTARTING, CURSOR_ID.HELP
- ]
- for id in cursors {
- DllCall("SetSystemCursor", "Ptr", DllCall("CopyImage", "Ptr", this.blankCursor
- , "Uint", 2, "Int", 0, "Int", 0, "Uint", 0), "Uint", id)
- }
- this.isHidden := true
- }
- static ShowCursor() {
- DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "UInt", 0, "UInt", 0)
- this.isHidden := false
- }
- static Cleanup() {
- this.ShowCursor()
- DllCall("DestroyCursor", "Ptr", this.blankCursor)
- }
- }
- ; Initialize cursor manager
- CursorManager.__New()
- ; Cleanup on
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement