AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CPU usage

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Babis



Joined: 08 Dec 2005
Posts: 45

PostPosted: Tue Oct 03, 2006 8:55 am    Post subject: CPU usage Reply with quote

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
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3644
Location: Belgrade

PostPosted: Tue Oct 03, 2006 10:18 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Andi



Joined: 11 Feb 2005
Posts: 157
Location: Germany, Niestetal

PostPosted: Tue Oct 03, 2006 8:23 pm    Post subject: Reply with quote

Try this... but I don't know, how to change the color Confused
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
View user's profile Send private message
mc



Joined: 25 Jan 2006
Posts: 2

PostPosted: Wed Oct 04, 2006 5:50 pm    Post subject: Reply with quote

majkinetor wrote:
...
Or you can draw icons real time, not to complex.. even histogram


How??? Question
Back to top
View user's profile Send private message
Carlol



Joined: 14 Aug 2006
Posts: 162
Location: CPH

PostPosted: Thu Oct 05, 2006 5:29 am    Post subject: Reply with quote

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
View user's profile Send private message
CarlosTheTackle



Joined: 19 Oct 2004
Posts: 102

PostPosted: Sun Jan 28, 2007 4:50 am    Post subject: Reply with quote

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
View user's profile Send private message
tonne



Joined: 06 Jun 2006
Posts: 1249
Location: Denmark

PostPosted: Sun Jan 28, 2007 7:29 am    Post subject: Reply with quote

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
View user's profile Send private message
CarlosTheTackle



Joined: 19 Oct 2004
Posts: 102

PostPosted: Sun Jan 28, 2007 8:32 am    Post subject: Reply with quote

Hey thanks, tonne. Much obliged.
Back to top
View user's profile Send private message
YMP



Joined: 23 Dec 2006
Posts: 266
Location: Russia

PostPosted: Sun Jan 28, 2007 10:42 am    Post subject: Reply with quote

Carlol wrote:

smaller font size?

Or larger button size. Wink
Code:

#Persistent
SetTimer, CheckCPULoad, 1000
ControlMove, Button1,,, 110,, ahk_class Shell_TrayWnd  ; Width = 110
return
Back to top
View user's profile Send private message
Carlol



Joined: 14 Aug 2006
Posts: 162
Location: CPH

PostPosted: Sun Jan 28, 2007 8:09 pm    Post subject: Reply with quote

Quote:
Or larger button size. Wink


YMP you're are regular Einstein, a question of relativity, thank you so much for removing a long time annoyance! Wink
Back to top
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Sun Jan 28, 2007 10:27 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
YMP



Joined: 23 Dec 2006
Posts: 266
Location: Russia

PostPosted: Mon Jan 29, 2007 5:57 am    Post subject: Reply with quote

@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
View user's profile Send private message
Carlol



Joined: 14 Aug 2006
Posts: 162
Location: CPH

PostPosted: Mon Jan 29, 2007 6:04 am    Post subject: Reply with quote

@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! Cool
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group