Advertisement
Enlight432

Untitled

Jan 22nd, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requires AutoHotkey v2.0
  2.  
  3. /*
  4.     Auto Hide Mouse Cursor
  5.     - Hides mouse cursor after 2 seconds of inactivity
  6.     - Shows cursor immediately on mouse movement
  7. */
  8.  
  9. ; Constants for cursor types
  10. class CURSOR_ID {
  11.     static ARROW := 32512
  12.     static IBEAM := 32513
  13.     static WAIT := 32514
  14.     static CROSS := 32515
  15.     static UPARROW := 32516
  16.     static SIZENWSE := 32642
  17.     static SIZENESW := 32643
  18.     static SIZEWE := 32644
  19.     static SIZENS := 32645
  20.     static SIZEALL := 32646
  21.     static NO := 32648
  22.     static HAND := 32649
  23.     static APPSTARTING := 32650
  24.     static HELP := 32651
  25. }
  26.  
  27. class CursorManager {
  28.     static __New() {
  29.         ; Initialize position variables
  30.         MouseGetPos(&x, &y)
  31.         this.lastX := x
  32.         this.lastY := y
  33.         this.isHidden := false
  34.         this.blankCursor := this.CreateBlankCursor()
  35.        
  36.         ; Set timers for movement check and auto-hide
  37.         SetTimer(this.CheckMouseMove.Bind(this), 100)
  38.         SetTimer(this.CheckIdleTime.Bind(this), 2000)
  39.     }
  40.    
  41.     static CreateBlankCursor() {
  42.         return DllCall("CreateCursor", "Uint", 0, "Int", 0, "Int", 0, "Int", 32, "Int", 32
  43.             , "Ptr", Buffer(32*4, 0xFF), "Ptr", Buffer(32*4, 0))
  44.     }
  45.    
  46.     static CheckMouseMove() {
  47.         MouseGetPos(&currentX, &currentY)
  48.         if (currentX != this.lastX || currentY != this.lastY) {
  49.             if (this.isHidden)
  50.                 this.ShowCursor()
  51.             this.lastX := currentX
  52.             this.lastY := currentY
  53.         }
  54.     }
  55.    
  56.     static CheckIdleTime() {
  57.         MouseGetPos(&currentX, &currentY)
  58.         if (currentX == this.lastX && currentY == this.lastY && !this.isHidden)
  59.             this.HideCursor()
  60.     }
  61.    
  62.     static HideCursor() {
  63.         static cursors := [
  64.             CURSOR_ID.ARROW, CURSOR_ID.IBEAM, CURSOR_ID.WAIT, CURSOR_ID.CROSS,
  65.             CURSOR_ID.UPARROW, CURSOR_ID.SIZENWSE, CURSOR_ID.SIZENESW,
  66.             CURSOR_ID.SIZEWE, CURSOR_ID.SIZENS, CURSOR_ID.SIZEALL,
  67.             CURSOR_ID.NO, CURSOR_ID.HAND, CURSOR_ID.APPSTARTING, CURSOR_ID.HELP
  68.         ]
  69.        
  70.         for id in cursors {
  71.             DllCall("SetSystemCursor", "Ptr", DllCall("CopyImage", "Ptr", this.blankCursor
  72.                 , "Uint", 2, "Int", 0, "Int", 0, "Uint", 0), "Uint", id)
  73.         }
  74.         this.isHidden := true
  75.     }
  76.    
  77.     static ShowCursor() {
  78.         DllCall("SystemParametersInfo", "UInt", 0x57, "UInt", 0, "UInt", 0, "UInt", 0)
  79.         this.isHidden := false
  80.     }
  81.    
  82.     static Cleanup() {
  83.         this.ShowCursor()
  84.         DllCall("DestroyCursor", "Ptr", this.blankCursor)
  85.     }
  86. }
  87.  
  88. ; Initialize cursor manager
  89. CursorManager.__New()
  90.  
  91. ; Cleanup on
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement