auto_Sleep_hibernation_Shutdown_PC_in_night

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

auto_Sleep_hibernation_Shutdown_PC_in_night

15 Aug 2018, 03:19

auto hibernation PC in night and your not using it.
:) enjoy

Code: Select all


#NoTrayIcon
#Persistent

isDemoMode := true
isDemoMode := False
SetTimer, checkItsDeepInNight, 400

Return

checkItsDeepInNight:
    ; A_Hour Current 2-digit hour (00-23) in 24-hour time
    milliSecIdle := A_TimeIdlePhysical ; milliseconds
    ; milliSecIdle := A_TimeIdle ; milliseconds
    secIdle := milliSecIdle / 1000
    minIdle := secIdle / 60

    isTime4pc2sleep := ( minIdle >= 90 && A_Hour >= 2 && A_Hour <= 4 )
    if(isDemoMode)
        isTime4pc2sleep := ( minIdle >= 0 && A_Hour >= 10 && A_Hour <= 11 ) 

    if(!isTime4pc2sleep)
        Return

    SetTimer,checkItsDeepInNight,Off
    msgSecWait := 120
    if(isDemoMode)
        msgSecWait := 5
    msgText := "you are sleeping (minIdle = " minIdle ") !!! :) `n PC will sleep in: " msgSecWait "sec (" A_LineFile " )"
    MsgBox, , %msgText% , %msgText%, % msgSecWait
    Goto, pc2sleep
Return

pc2sleep:
    secWait := 120
    if(isDemoMode)
        secWait := 5
    msgText := "PC will sleep in " secWait "sec"
    MsgBox, , %msgText% , %msgText%, % secWait
    ; Sleep/Suspend:  https://gist.github.com/davejamesmiller/1965847

    if(!isDemoMode)
        DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
    ; Hibernate:  https://gist.github.com/davejamesmiller/1965847
    ;DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return


User avatar
SL5
Posts: 879
Joined: 12 May 2015, 02:10
Contact:

Re: auto_Sleep_hibernation_Shutdown_PC_in_night

24 Aug 2018, 01:30

Code: Select all

; Indentation_style: https://de.wikipedia.org/wiki/Einrückungsstil#SL5small-Stil
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; isDevellopperMode:=true ; enth�llt auch update script.
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Include *i %A_ScriptDir%\inc_ahk\init_global.init.inc.ahk
#Persistent


msgSecWait := 5
msgText := " i am stated just now  :-) (" A_LineFile " )"
MsgBox, , %msgText% , %msgText%, % msgSecWait



; #NoTrayIcon

; https://autohotkey.com/boards/viewtopic.php?f=6&t=54081
isDemoMode := true
isDemoMode := False
SetTimer, checkItsDeepInNight, 4000

Return

checkItsDeepInNight:
    ; A_Hour Current 2-digit hour (00-23) in 24-hour time
    milliSecIdle := A_TimeIdlePhysical ; milliseconds
    ; milliSecIdle := A_TimeIdle ; milliseconds
    secIdle := 0
    minIdle := 0
    hourIdle := 0
    if(milliSecIdle > 0){ ; probalby (nearly) always the case
        secIdle := milliSecIdle / 1000
        minIdle := secIdle / 60
        hourIdle := minIdle / 60
    }

    isTime4pc2sleep := ( minIdle >= 80 && A_Hour >= 2 && A_Hour <= 5 )
    if(!isTime4pc2sleep)
        isTime4pc2sleep := ( hourIdle >= 2 )

    if(isDemoMode)
        isTime4pc2sleep := ( minIdle >= 0 && A_Hour >= 10 && A_Hour <= 11 ) 


    if(!isTime4pc2sleep)
        Return

    SetTimer,checkItsDeepInNight,Off
    msgSecWait := 120
    if(isDemoMode)
        msgSecWait := 5
    msgText := "you are sleeping (minIdle = " minIdle ") !!! :) `n PC will sleep in: " msgSecWait "sec (" A_LineFile " )"
    MsgBox, , %msgText% , %msgText%, % msgSecWait
    Goto, pc2sleep
Return

pc2sleep:
    secWait := 120
    if(isDemoMode)
        secWait := 5
    msgText := "PC will sleep in " secWait "sec"
    MsgBox, , %msgText% , %msgText%, % secWait
    ; Sleep/Suspend:  https://gist.github.com/davejamesmiller/1965847

    if(!isDemoMode){
        FormatTime, timestampyyMMddHHmmssPrettShort, %A_now%,dd.MM.yyyy HH:mm
        tip := "hourIdle = " hourIdle " ( " timestampyyMMddHHmmssPrettShort " - " A_LineFile " - " A_LoopField " - " SetSuspendState " ) "
        ToolTip, % tip
        Clipboard := tip
        DllCall("PowrProf\SetSuspendState", "int", 0, "int", 0, "int", 0)
        Pause ; easier tooo find it. if its in pause state suspend should have happens
    }
    ; Hibernate:  https://gist.github.com/davejamesmiller/1965847
    ;DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0)
Return

#Include *i %A_ScriptDir%\inc_ahk\functions_global.inc.ahk
;#Include %A_ScriptDir%\inc_ahk\copy2clipBoard.functions.inc.ahk
;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;~ subroutinen beispielsweise m�sen ans Dateiende
#Include *i %A_ScriptDir%\inc_ahk\functions_global_dateiende.inc.ahk
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Include *i %A_ScriptDir%\inc_ahk\UPDATEDSCRIPT_global.inc.ahk

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: ArkuS and 70 guests