Advertisement
eptesicus

Untitled

Nov 21st, 2023
1,337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Reference: https://www.reddit.com/r/AutoHotkey/comments/rog13v/comment/hq96cky/
  2.  
  3. ; ## Autoexecution ##
  4. #Persistent
  5. Menu, Tray, Icon, %A_ScriptDir%\images\icon.ico
  6. #SingleInstance Force
  7. SetBatchLines -1
  8. SetTimer tDim, 250
  9. vBrt := 255  ; Initial Brightness (Don't change!)
  10.  
  11. ; #### Play Area Variables ####
  12. vDur := 1       ; Number of minutes to wait
  13. vMin := 70      ; Minimum dimness level (0-254)
  14. dRng := 4       ; Dimming frame skip (lower/slower)
  15. dDly := 15      ; Number of ms between dimming frames
  16. uRng := 8       ; Lighting frame skip (lower/slower)
  17. uDly := 15      ; Number of ms between lighting frames (0/Instant)
  18. wWidth := 10320 ; Total width of all displays
  19. wHeight := 1440 ; Total height of all displays
  20. xPos := -3440   ; Starting position of leftmost display
  21. yPos := 0       ; Starting position of leftmost display
  22.  
  23. ; #### Gui Build ####
  24. Gui Dimmer:New, +AlwaysOnTop +ToolWindow -Caption +E0x20
  25. Gui Color, 000000
  26. Gui Dimmer:Show, NoActivate x%xPos% y%yPos% w%wWidth% h%wHeight%, Dimmer
  27. WinSet Transparent, 0, Dimmer
  28. Gui Hide
  29.  
  30. ; #### Main Code ####
  31. tDim:
  32.    ; Check for both mouse movement and keyboard activity
  33.     If (A_TimeIdle > (vDur * 60000) || A_TimeSincePriorHotkey > (vDur * 1000)) && !fChk {
  34.         MouseGetPos mX, mY
  35.         BlockInput MouseMove
  36.         MouseMove wWidth, wHeight, 0
  37.         Gui Dimmer:Show, NoActivate
  38.         WinSet AlwaysOnTop, On, Dimmer
  39.         If fU {
  40.             SetTimer tU, Off
  41.             fU := 0
  42.         }
  43.         SetTimer tD, % dDly
  44.         fD := 1, fChk := 1
  45.     } Else If (A_TimeIdle < 200) && fChk {
  46.         MouseMove mX, mY, 0
  47.         BlockInput MouseMoveOff
  48.         If fD {
  49.             SetTimer tD, Off
  50.             fD := 0
  51.         }
  52.         If !uDly {
  53.             WinSet Transparent, % 255 - (vBrt := 255), Dimmer
  54.         } Else {
  55.             SetTimer tU, % uDly
  56.             fU := 1
  57.         }
  58.         While fU {
  59.             ; Allow other events to be processed during the delay
  60.             Critical, Off
  61.             Sleep, 10
  62.             Critical, On
  63.         }
  64.         WinSet AlwaysOnTop, Off, Dimmer
  65.         Gui Dimmer:Hide
  66.         fChk := 0
  67.     }
  68.     Return
  69.  
  70. ; ##### Timers ######
  71. tD:
  72.    vBrt -= dRng
  73.     If (vBrt <= vMin)
  74.         vBrt := vMin
  75.     WinSet Transparent, % 255 - vBrt, Dimmer
  76.     If (vBrt = vMin) {
  77.         SetTimer tD, Off
  78.         fD := 0
  79.     }
  80.     Return
  81.  
  82. tU:
  83.    vBrt += uRng
  84.     If (vBrt >= 255)
  85.         vBrt := 255
  86.     WinSet Transparent, % 255 - vBrt, Dimmer
  87.     If (vBrt = 255) {
  88.         SetTimer tU, Off
  89.         fU := 0
  90.     }
  91.     Return
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement