Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;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.
- ;CONFIGURATION
- WaitTime=1600 ;Time in Seconds to be idle before shutting down.
- DefaultVolume=40 ;Volume in Percent to start at and reset to user activity detected.
- #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
- ;#Warn ; Enable warnings to assist with detecting common errors. -- BREAKS GUI
- #SingleInstance Force
- SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
- SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
- Print(vOutput)
- {
- static hGui, hEdit, vText, vWinW := 400, vWinH := 400
- if !hGui
- {
- Gui, New, +HwndhGui
- Gui, +AlwaysOnTop
- Gui, Font, s18 w700 cC0C0C0, Courier New
- Gui, Color,, 000000
- Gui, Add, Edit, % Format("+HwndhEdit x0 y0 w{} h{}", vWinW, vWinH)
- Gui, Show, % Format("w{} h{}", vWinW, vWinH)
- vText := vOutput
- }
- else
- {
- ControlGetText, vText,, % "ahk_id " hEdit
- vText .= "`r`n" vOutput
- }
- ControlSetText,, % vText, % "ahk_id " hEdit
- vLen := StrLen(vText)
- SendMessage, 0xB1, % vLen, % vLen,, % "ahk_id " hEdit ;EM_SETSEL := 0xB1
- PostMessage, 0xB7, 0, 0,, % "ahk_id " hEdit ;EM_SCROLLCARET := 0xB7
- }
- ;Minimizing reduces BlueStacks and Eve Online power usage.
- WinMinimizeAll
- Print("Press Esc to cancel shutdown")
- sleep, 1000
- SendMessage,0x112,0xF170,2,,ahk_id 0xFFFF ;Turn off monitor
- Loop
- {
- sleep, 1000
- idle:=round(A_TimeIdle/1000)
- shutdownIn:=WaitTime-idle
- SoundSet, Max(0,DefaultVolume-idle)
- Print("FORCIBLE shutdown in " shutdownIn)
- if (shutdownIn<0) {
- Shutdown, 5
- }
- }
- ExitApp
- Escape::
- SoundSet, DefaultVolume
- ExitApp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement