 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Babis
Joined: 08 Dec 2005 Posts: 45
|
Posted: Tue Oct 03, 2006 8:55 am Post subject: CPU usage |
|
|
Hi. I am using a "cpu usage" script by Laszlo, trimmed by evl.
This script displays the cpu usage numerically at the start button.
I am trying to personalize it (without success), in way that it will show numbers in white when the cpu usage is 1-33, orange when usage is 34-66 and red when 67-100.
Please guide/advise
Thanks.
| Code: | #Persistent
SetTimer, CheckCPULoad, 1000
return
CheckCPULoad:
SetFormat, float, 02
ControlSetText, Button1, % " " GetCPULoad() " %", ahk_class Shell_TrayWnd
return
GetCPULoad()
{
Global
SetBatchLines, -1
IdleTime0 = %IdleTime% ; Save previous values
Tick0 = %Tick%
DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
IdleTime := *(&IdleTicks)
Loop 7 ; Ticks when Windows was idle
IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
Tick := A_TickCount ; Ticks all together
load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
Return, load
} |
|
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3644 Location: Belgrade
|
Posted: Tue Oct 03, 2006 10:18 am Post subject: |
|
|
Hm... very annoying to have it in start button
Plus everybody that use themes will not be able to see it.
You should examine dynamic tray icons.
For instance you can create 10 icons and when Xn <cpu<Xn+1 you can present Xn icon.
Or you can draw icons real time, not to complex.. even histogram _________________
 |
|
| Back to top |
|
 |
Andi
Joined: 11 Feb 2005 Posts: 157 Location: Germany, Niestetal
|
Posted: Tue Oct 03, 2006 8:23 pm Post subject: |
|
|
Try this... but I don't know, how to change the color
| Code: | #Persistent
SetTimer, CheckCPULoad, 1000
return
CheckCPULoad:
SetFormat, float, 02
ControlSetText, Button1, % GetCPULoad(), ahk_class Shell_TrayWnd
return
GetCPULoad()
{
Global
SetBatchLines, -1
IdleTime0 = %IdleTime% ; Save previous values
Tick0 = %Tick%
DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
IdleTime := *(&IdleTicks)
Loop 7 ; Ticks when Windows was idle
IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
Tick := A_TickCount ; Ticks all together
load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
Return, load
}
|
|
|
| Back to top |
|
 |
mc
Joined: 25 Jan 2006 Posts: 2
|
Posted: Wed Oct 04, 2006 5:50 pm Post subject: |
|
|
| majkinetor wrote: | ...
Or you can draw icons real time, not to complex.. even histogram |
How???  |
|
| Back to top |
|
 |
Carlol
Joined: 14 Aug 2006 Posts: 162 Location: CPH
|
Posted: Thu Oct 05, 2006 5:29 am Post subject: |
|
|
Not to hijack the thread but a related request:
I'm also very fond of Lazlo's script:
| Code: | #Persistent
SetTimer, CheckCPULoad, 1000
return
CheckCPULoad:
SetFormat, float, 02
ControlSetText, Button1, % " " GetCPULoad() " %", ahk_class Shell_TrayWnd
return
GetCPULoad()
{
Global
SetBatchLines, -1
IdleTime0 = %IdleTime% ; Save previous values
Tick0 = %Tick%
DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
IdleTime := *(&IdleTicks)
Loop 7 ; Ticks when Windows was idle
IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
Tick := A_TickCount ; Ticks all together
load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
Return, load
} |
But my problem is that my start button is not big enough to accomodate the full text, so I've modified the script removing the space in front of the % sign, but when I reach a load of a hundred the % sign "falls" out of the picture, anyway to fix this, smaller font size? Thanks for listening! |
|
| Back to top |
|
 |
CarlosTheTackle
Joined: 19 Oct 2004 Posts: 102
|
Posted: Sun Jan 28, 2007 4:50 am Post subject: |
|
|
Hi there, just stumbled across this script when looking for a method of monitoring CPU usage, and it looks promising.
However, when running (exactly as posted above), I get this error:
| Quote: |
Error: This DllCall requires a prior VarSetCapacity. The program is now unstable and will exit.
Line#
023: SetFormat,float,02
024: ControlSetText,Button1," " GetCPULoad() " %",ahk_class Shell_TrayWnd
025: Return
028: {
030: SetBatchLines,-1
031: IdleTime0 = %IdleTime%
032: Tick0 = %Tick%
---> 033: DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
034: IdleTime := *(&IdleTicks)
035: Loop,7
036: IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
037: Tick := A_TickCount
038: load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
039: Return,load
040: }
|
Obviously this requires an earlier VarSetCapacity, but what exactly? And why did no one else have this problem. Is it to do with a new version of AHK? |
|
| Back to top |
|
 |
tonne
Joined: 06 Jun 2006 Posts: 1249 Location: Denmark
|
Posted: Sun Jan 28, 2007 7:29 am Post subject: |
|
|
Yes, it's new.
Use VarSetCapacity(IdleTicks,8,0) before the DllCall to allocate 8 bytes initialized with 0 for the variable. _________________ there's a dog barking close within the range of my ear
sounds like he wants to escape the chain
he would probably bite me to death if he could
but the chain lets me spit in his face
- Kashmir |
|
| Back to top |
|
 |
CarlosTheTackle
Joined: 19 Oct 2004 Posts: 102
|
Posted: Sun Jan 28, 2007 8:32 am Post subject: |
|
|
| Hey thanks, tonne. Much obliged. |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 266 Location: Russia
|
Posted: Sun Jan 28, 2007 10:42 am Post subject: |
|
|
| Carlol wrote: |
smaller font size?
|
Or larger button size.
| Code: |
#Persistent
SetTimer, CheckCPULoad, 1000
ControlMove, Button1,,, 110,, ahk_class Shell_TrayWnd ; Width = 110
return
|
|
|
| Back to top |
|
 |
Carlol
Joined: 14 Aug 2006 Posts: 162 Location: CPH
|
Posted: Sun Jan 28, 2007 8:09 pm Post subject: |
|
|
| Quote: | Or larger button size. |
YMP you're are regular Einstein, a question of relativity, thank you so much for removing a long time annoyance!  |
|
| Back to top |
|
 |
Veovis
Joined: 13 Feb 2006 Posts: 390 Location: Utah
|
Posted: Sun Jan 28, 2007 10:27 pm Post subject: |
|
|
| majkinetor wrote: | | Or you can draw icons real time, not to complex.. even histogram |
I am very interested in hearing how excactly one might do this _________________
"Power can be given overnight, but responsibility must be taught. Long years go into its making." |
|
| Back to top |
|
 |
YMP
Joined: 23 Dec 2006 Posts: 266 Location: Russia
|
Posted: Mon Jan 29, 2007 5:57 am Post subject: |
|
|
@Carlol
Well, but it's turned out to be not quite so simple. The taskbar seems to update itself from time to time, in response to some events, and the button's size is brought back to its defaults. So it may be better to insert the resizing command into the timer's code to make it execute periodically. It may also make sense to shift the button to the left to partially compensate its larger size.
| Code: |
CheckCPULoad:
ControlMove, Button1, -7,, 110,, ahk_class Shell_TrayWnd
SetFormat, float, 02
ControlSetText, Button1, % " " GetCPULoad() " %", ahk_class Shell_TrayWnd
return
|
|
|
| Back to top |
|
 |
Carlol
Joined: 14 Aug 2006 Posts: 162 Location: CPH
|
Posted: Mon Jan 29, 2007 6:04 am Post subject: |
|
|
@YMP
Funny you should come in this very moment, I've was just trying to solve this problem by placing:
| Code: | | ControlMove, Button1,,, 110,, ahk_class Shell_TrayWnd ; Width = 110 |
In different places in the script, but to no avail, now I will look into your new ideas...Thanks!  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|