Hello. this is a little script i added onto the getcpuload function. When the cpu usage becomes too high it will set the priority of the active window to low. when the cpu usage goes down, it's set back to normal.
Code:
#Persistent
IdleTicks = 0000
GetCPULoad()
{
Global
SetBatchLines, -1
IdleTime0 = %IdleTime%
Tick0 = %Tick%
DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
IdleTime := *(&IdleTicks)
Loop 7
IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
Tick := A_TickCount
load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
Return, load
}
settimer,cputimer,1000
cputimer:
winget, pid, PID, A
if % GetCPULoad() > 80
{
process, priority, %pid%, L
} else {
process, priority, %pid%, N
}
Return
I think it might be a good idea to log which processes' priorities were changed so the user doesn't need to activate them to set them back to normal. And possibly only change the priorities if the cpu level has exceeded the constant for a number of seconds so it doesn't notice spikes.
I'd also like to only change the priorities of the process which are causing the cpu overload, but i don't think that's possible.