How to determine the amount of RAM and amount in use Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

How to determine the amount of RAM and amount in use

19 Jan 2018, 12:13

Hi Folks,
I've been using an app for many years to show the percentage of physical memory (RAM) that is in use. It places an icon in the system tray with the percentage figure and hovering on the icon gives a tray tip with more info. Looks like this:
memory used.gif
memory used.gif (3.86 KiB) Viewed 1698 times
I'd like to write an AHK script for this, but don't know how to get the amount of RAM installed in the machine or the amount of RAM used. Anyone know how to retrieve those two values? Thanks much, Joe
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: How to determine the amount of RAM and amount in use

19 Jan 2018, 16:06

Perfect! Thanks to RickC for pointing me to the post and to jNizM for yet another superb AHK script! Regards, Joe
garry
Posts: 3758
Joined: 22 Dec 2013, 12:50

Re: How to determine the amount of RAM and amount in use

19 Jan 2018, 16:58

thank you jNizM , glad to clear memory
I have longtime this script ( link in a_startupcommon ) , hover startbutton , see [ CPU / Memory / Time , date ]

Code: Select all

;MODIFIED=20110807
;CREATED =20060226

/*
This helpful script didn't count with multi core CPU.
I have included 1 line, where I've found out number of
(logical, I hope that it is correct) processors and then only I'v divided total_idle_ticks by this

-EnvGet, ProcessorCount, NUMBER_OF_PROCESSORS
-load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0) / ProcessorCount

;-- http://www.autohotkey.com/forum/post-334034.html#334034
*/


;-- http://www.autohotkey.com/forum/post-226003.html#226003
;-- http://www.autohotkey.com/forum/topic17234.html             ;-- number of CPU cores
;-- http://www.autohotkey.com/forum/viewtopic.php?t=6144#36851  ;-- memgetstats
;-----------------

/*
hover Start Button / Clock with cpu and memory usage bars.  a_startupcommon
  - default positions/size for Windows XP classic appearance (old style windows look).
*/



;============================================================================================
#NoTrayIcon                ; Save space w/o icon/menu
Process Priority,,High

;----- edit here for best look -----

X_Pos = 0 ; x co-ordinate on taskbar
Y_Pos = 0 ; y co-ordinate on taskbar

Clock_Width   = 58             ; width of the clock and progress bars (fit to taskbar)
ProgressBar_H = 8              ; height of the progress bars


CPU_Usage_Bar_Color = Navy
Mem_Usage_Bar_Color = Red

Clock_Color      = White          ; Background
Clock_Font_Color = Black          ; Font
Clock_Font       = Arial
Clock_Pts        = 10
Clock_Font_Style = bold
Clock_Pattern    = h:mm:ss
Clock_H          = 14             ; height of the clock




;----- code starts here -----
EnvGet, ProcessorCount, NUMBER_OF_PROCESSORS       ;-- added new

;VarSetCapacity( IdleTicks,    2*4 )
VarSetCapacity( IdleTicks,8,0)
VarSetCapacity( memorystatus, 100 )


Menu ClockMenu, Add, &Adjust Date/Time, DTSet
Menu ClockMenu, Add, &Copy Date/Time, DTcopy
Menu ClockMenu, Add, E&xit,  7GuiClose
Menu ClockMenu, Add, Canc&el,DTCancel


;------------- GUI ----------------------------------
; seperate gui for each thing to allow cropping of borders for maximum space

;---------- Clock ----------------
Gui, 7: Margin, 0, 0
Gui, 7: -Caption +ToolWindow           ;-- no title, no taskbar icon
Gui, 7: Color, %Clock_Color%
Gui, 7: font, S%Clock_Pts% %Clock_Font_Style% c%Clock_Font_Color%, %Clock_Font%
Gui, 7: Add, Text, x5 y-1 vClock w%Clock_Width% h%Clock_H% vDT

;---------- CPU -----------------
ProgressBar_W := Clock_Width +4
Gui, 8: Margin, 0, 0
Gui, 8: -Caption +ToolWindow            ;-- no title, no taskbar icon
Gui, 8: Add, Progress, vProcLoad x-2 y-2 w%ProgressBar_W% h%ProgressBar_H% c%CPU_Usage_Bar_Color%


;---------- Memory ---------------
Gui, 9: Margin, 0, 0
Gui, 9: -Caption +ToolWindow            ;-- no title, no taskbar icon
Gui, 9: Add, Progress, vMemLoad x-2 y-2 w%ProgressBar_W% h%ProgressBar_H% c%Mem_Usage_Bar_Color%



Bar_H := ProgressBar_H - 4 ; 2*2 border pixels
Bar_H_plus_Clock_H := Bar_H + Clock_H


Gui, 7: Show, x%X_Pos% y%Bar_H% w%Clock_Width% h%Clock_H%, Clock
Gui, 8: Show, x%X_Pos% y%Y_Pos% w%Clock_Width% h%Bar_H%, Processor Load
Gui, 9: Show, x%X_Pos% y%Bar_H_plus_Clock_H% w%Clock_Width% h%Bar_H%, Memory Load

Dock2TaskBar(7)
Dock2TaskBar(8)
Dock2TaskBar(9)

SetTimer ClockUpdate, 1000 ; Update bars, redraw clock, tooltip
OnMessage(0x200,"Hover")   ; 0x200 = WM_MOUSEMOVE used instead of WM_MOUSEHOVER
OnMessage(0x201,"LClick")  ; 0x201 = WM_LBUTTONDOWN
Return
;------------------------------------------------



ClockUpdate:
  FormatTime time,,%Clock_Pattern%
  GuiControl 7:,DT,%time%                 ;-- Update date/time in preset format

  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) / ProcessorCount    ; -- modified /processorcount
  GuiControl 8: , ProcLoad, %load%         ;-- Update progress bar




  DllCall("kernel32.dll\GlobalMemoryStatus", "uint",&memorystatus)
  mem := *( &memorystatus + 4 ) ; last byte is enough, mem = 0..100
  GuiControl 9: , MemLoad, %mem%           ;-- Update progress bar
Return
;----------------------------------------------------



DTCancel:                  ; Do nothing in popup menu
Return
;-------------------------------------------------------------------



7GuiContextMenu:           ; Right click popup menu
  ToolTip                  ; Erase
  Menu ClockMenu, Show     ; Show context menu
Return
;-------------------------------------------------------------------



7GuiClose:                 ; Exit
  ExitApp
;-------------------------------------------------------------------



DTSet:                     ; Adjust date and time
  Run timedate.cpl
Return
;-------------------------------------------------------------------



DTcopy:                    ; Copy Date/Time to the ClipBoard
  Clipboard := FullDT()
Return
;-------------------------------------------------------------------



LClick()                   ; show start menu
{
  Send, {LWIN}
}
;-------------------------------------------------------------------




Hover()                    ; When the mouse hovers DT
{
  Global load, mem

  If A_Gui = 7                           ;-- Mouse cursor hovers DT control
    {
    ToolTip, % FullDT()                  ;-- Show full date/time info
    SetTimer, Check_If_Mouse_Not_Hover, 500
    Return
    }

   If A_Gui = 8                           ;-- Mouse cursor hovers DT control
    {
    SetFormat, float, 0.0
    load := load + 0
    ToolTip, % "CPU: " load "%"           ;-- Show cpu usage
    SetTimer, Check_If_Mouse_Not_Hover, 500
    Return
    }

   If A_Gui = 9                            ;-- Mouse cursor hovers DT control
    {
    ToolTip, % "Memorage used: " mem "%"   ;-- Show memory usage
    SetTimer, Check_If_Mouse_Not_Hover, 500
    Return
    }

   ToolTip              ; Erase
}
;-------------------------------------------------------------------




;---------- Mouse -Hoverx ------------------------------------------
Check_If_Mouse_Not_Hover:
  MouseGetPos,,, Mouse_Over_Win
  If Mouse_Over_Win not contains %Gui_ID_7%, %Gui_ID_8%, %Gui_ID_9%
    {
    Tooltip ; hide tooltip
    SetTimer, Check_If_Mouse_Not_Hover, Off
    }
Return
;-------------------------------------------------------------------



Dock2TaskBar(Gui_Number)              ;-- Active window to be docked to the taskbar, NEEDS hw_tray value
{
  Global ; for checking tooltip with mousegetpos
  hw_tray := DllCall( "FindWindowEx", "uint",0, "uint",0, "str","Shell_TrayWnd", "uint",0 )
  Gui, %Gui_Number%: +LastFound
  Gui_ID_%Gui_Number% := WinExist()
  DllCall( "SetParent", "uint", Gui_ID_%Gui_Number%, "uint", hw_tray )
}
;-------------------------------------------------------------------



FullDT()                               ;-- Returns current date/time info
{
  FormatTime wday,,dddd
  FormatTime day,, yDay
  FormatTime week,,yWeek
  StringTrimLeft week, week, 4
  ;----- edit here for best look -----
  ;FormatTime DT,,d MMMM yyyy
  FormatTime DT,,d MMMM yyyy

  ;Return wday " " DT "   (Day: " day ", Week: " week ")"
  Return DT
  ;Return %nothing%
  ;----- edit here for best look -----
}
;============================= END script =================

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot] and 243 guests