Advertisement
gmatht

EvShutdown.ahk

Nov 10th, 2022
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 1.80 KB | Source Code | 0 0
  1. ;Script to FORCIBLY shutdown computer after a delay (Save your documents before running this script. Turns of monitor, gradually mutes sound. Also minimises windows to save power.
  2.  
  3. ;CONFIGURATION
  4. WaitTime=1600    ;Time in Seconds to be idle before shutting down.
  5. DefaultVolume=40 ;Volume in Percent to start at and reset to user activity detected.
  6.  
  7.  
  8. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  9. ;#Warn  ; Enable warnings to assist with detecting common errors. -- BREAKS GUI
  10. #SingleInstance Force
  11. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  12. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  13.  
  14.  
  15. Print(vOutput)
  16. {
  17.     static hGui, hEdit, vText, vWinW := 400, vWinH := 400
  18.     if !hGui
  19.     {
  20.         Gui, New, +HwndhGui
  21.         Gui, +AlwaysOnTop
  22.         Gui, Font, s18 w700 cC0C0C0, Courier New
  23.         Gui, Color,, 000000
  24.         Gui, Add, Edit, % Format("+HwndhEdit x0 y0 w{} h{}", vWinW, vWinH)
  25.         Gui, Show, % Format("w{} h{}", vWinW, vWinH)
  26.         vText := vOutput
  27.     }
  28.     else
  29.     {
  30.         ControlGetText, vText,, % "ahk_id " hEdit
  31.         vText .= "`r`n" vOutput
  32.     }
  33.     ControlSetText,, % vText, % "ahk_id " hEdit
  34.     vLen := StrLen(vText)
  35.     SendMessage, 0xB1, % vLen, % vLen,, % "ahk_id " hEdit ;EM_SETSEL := 0xB1
  36.     PostMessage, 0xB7, 0, 0,, % "ahk_id " hEdit ;EM_SCROLLCARET := 0xB7
  37. }
  38.  
  39. ;Minimizing reduces BlueStacks and Eve Online power usage.
  40. WinMinimizeAll
  41.  
  42. Print("Press Esc to cancel shutdown")
  43.  
  44. sleep, 1000
  45. SendMessage,0x112,0xF170,2,,ahk_id 0xFFFF   ;Turn off monitor
  46.  
  47.  
  48. Loop
  49. {
  50.     sleep, 1000
  51.     idle:=round(A_TimeIdle/1000)
  52.     shutdownIn:=WaitTime-idle
  53.     SoundSet, Max(0,DefaultVolume-idle)
  54.     Print("FORCIBLE shutdown in " shutdownIn)
  55.     if (shutdownIn<0) {
  56.         Shutdown, 5
  57.     }
  58. }
  59.  
  60.  
  61. ExitApp
  62.  
  63. Escape::
  64. SoundSet, DefaultVolume
  65. ExitApp
  66.  
Tags: ahk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement