Instead i offer this little solution which only prevents system standby but allows your monitor to go into a standby states. This is perfect for PPL that use their PC for large number crunching tasks like 3D rendering, video encoding or data compression.
Code: Select all
Loop
Loop
{
Sleep 30000 ;Sleep timer to avoud high cpu usage. 30s ensures 2 checks per min, so even 1 min standby time works
if A_TimeIdle > 20000 ; verify if machine has been "idle" more than 20 sek.
{
CPULoad() ;init of CPULoad() check
PwrPrevState:=0 ;init of Power prevent states variabel
While A_TimeIdle > 20000
{
Sleep 9999 ; Sleep timer to both reduce cpu and get time for CPUload() to get a good tome to average over
Check:=CPULoad()
if (Check > 8) ; Checks if CPU load is above 8%
{
Gosub, PrevStandby ; Calls the prevent standby routine. since CPU load is high
}
else
{
Gosub, AllowStandby ; calls the enable standby routine since CPU load is low
}
}
}
Gosub, AllowStandby ; calls the enable standby routine since idletime is low,
}
Return
; The pwrprevstate variable is a only there to save unneeded DLLcalls and thereby decrease overall cpu usage
; if you don't want it, you can remove the init above and replace the gosub calls with the corresponding DLLcalls's
; and remove the two labels/functions below
CPULoad()
{
static PIT, PKT, PUT
static CIT, CKT, CUT
static ST
PIT := CIT
PKT := CKT
PUT := CUT
DllCall( "GetSystemTimes", "Int64P",CIT, "Int64P",CKT, "Int64P",CUT )
ST := ((PKT - CKT) + (PUT - CUT))
Return (( ST - (PIT - CIT)) * 100 ) // ST
}
PrevStandby:
if PwrPrevState = 0
{
PwrPrevState:=1
DllCall("Kernel32\SetThreadExecutionState" , "UInt", 0x80000001) ;prevents system but not monitor to go standby
}
return
AllowStandby:
if PwrPrevState = 1
{
PwrPrevState:=0
DllCall("Kernel32\SetThreadExecutionState" , "UInt", 0x80000000) ; Allows standby again.
}
return
Sorry for the disorganized code but i hope somebody can form/use it for something.