What is it?This is a function that will work out the total up time of your pc since it was restarted, in (WW:DD:)HH:MM:SS where by it will only show untits that are not 0. eg> 12:42:25 instead of 00:00:12:42:25.
It stores the time in the Variable "UpTime"
Why
I spend bout half an hour work on this function, because the program that does it for me is really annoing. so it had to be ahk.
If some one needs it:
UpTime Function
;By Leo @ [email protected] SetTimer, UpTimeTimer , 1000 ; This bit in the auto Execution section(top bit) UpTimeTimer: ; ToTal*unit*, "//"" gets rid of the uneccessary decimals ;*for use in the next bit. TTMilliseconds := A_TickCount TTSeconds := A_TickCount // 1000 ;*1000 Mil secs in a second TTMinutes := A_TickCount // 60000 ; *60 secs in an minute TTHours := A_TickCount // 3600000 ; *60 Mins in an hour TTDays := A_TickCount // 86400000 ; *24 hours in a day TTWeeks := A_TickCount // 604800000 ; *52 weeks in a year. ;-) ; This bit works out the exact timing. an example would be,, you cant display 700 Totatl ; Mintues, so you work out the unneccessary 11 hours (11 * 60 = 660) ; and take them of the total 700 - 660 = 40 Minutes. And you got what you want. Milliseconds := TTMilliseconds - (1000 * (TTMilliseconds // 1000)) Seconds := TTSeconds - (60 * (TTSeconds // 60)) Minutes := TTMinutes - (60 * (TTMinutes // 60)) Hours := TTHours - (24 * (TTHours // 24)) Days := TTDays - (7 * (TTDays // 7)) Weeks := TTWeeks - (52 * (TTWeeks // 52)) ;This is for determination of wheter or not the ":" Colon and time digits should be displayed, ;(other wise it'll show some thing like 00:00:12:42:25 instead of 12:42:25) If Weeks >= 1 Wc = %Weeks%: ;Wc as in Weeks coloums If Days >= 1 Dc = %Days%: If Hours >= 1 Hc = %Hours%: If Minutes >= 1 Mc = %Minutes%: UpTime = %Wc%%Dc%%Hc%%Mc%%Seconds% ;:%Milliseconds% ;its upto you to include Mili secs, i dont like them. ;ToolTip, %UpTime% ;`nTTHours = %Hours% `n Minutes = %Minutes% `n Seconds = %Seconds% Return
[EDIT]
Up time OSD
I've used the example On Screen display script in the gui section and tweaked it around a little, and here we go.
You will get the time in the bottom right corner of your screen, units only.
Version 2.
;By Leo @ [email protected] ; make sure to have this either in the auto execution section ;-------------------------This in the auto execution section------------- SetTimer, UpTimeTimer , 1000 ;these 2 serve the purpose of uptime GoSub, MyUptimeguiOSD ; Gui bit of the OSD ;-------------------------------The below any where you want--------------- MyUptimeguiOSD: CustomColor = EEAA99 ; Can be any RGB color (it will be made transparent below). Gui, +AlwaysOnTop +LastFound +Owner ; +Owner prevents a taskbar button from appearing. Gui, Color, %CustomColor% Gui, Font, s20 Gui, Add, Text, vMyText cLime, XXXXX YYYYY ; XX & YY serve to auto-size the window. ; Make all pixels of this color transparent and make the text itself translucent (150): WinSet, TransColor, %CustomColor% 150 Gui, -Caption ; Remove the title bar and window borders. GuiControl,, MyText, %UpTime% ; < this was in the timer (got moved to my one) x := A_ScreenWidth - 135 ;this and the below bit makes sure it works on every pc y := A_ScreenHeight - 104 ; by adjusting the postion of the OSD of the current screen res. Gui, Show, x%x% y%y% return UpTimeTimer: ; ToTal*unit*, "//"" gets rid of the uneccessary decimals ;*for use in the next bit. TTMilliseconds := A_TickCount TTSeconds := A_TickCount // 1000 ;*1000 Mil secs in a second TTMinutes := A_TickCount // 60000 ; *60 secs in an minute TTHours := A_TickCount // 3600000 ; *60 Mins in an hour TTDays := A_TickCount // 86400000 ; *24 hours in a day TTWeeks := A_TickCount // 604800000 ; *52 weeks in a year. ;-) ; This bit works out the exact timing. an example would be,, you cant display 700 Totatl ; Mintues, so you work out the unneccessary 11 hours (11 * 60 = 660) ; and take them of the total 700 - 660 = 40 Minutes. And you got what you want. Milliseconds := TTMilliseconds - (1000 * (TTMilliseconds // 1000)) Seconds := TTSeconds - (60 * (TTSeconds // 60)) Minutes := TTMinutes - (60 * (TTMinutes // 60)) Hours := TTHours - (24 * (TTHours // 24)) Days := TTDays - (7 * (TTDays // 7)) Weeks := TTWeeks - (52 * (TTWeeks // 52)) ;This is for determination of wheter or not the ":" Colon and time digits should be displayed, ;(other wise it'll show some thing like 00:00:12:42:25 instead of 12:42:25) If Weeks >= 1 Wc = %Weeks%: ;Wc as in Weeks coloums If Days >= 1 Dc = %Days%: If Hours >= 1 Hc = %Hours%: If Minutes >= 1 Mc = %Minutes%: UpTime = %Wc%%Dc%%Hc%%Mc%%Seconds% ;:%Milliseconds% ;its upto you to include Mili secs, i dont like them. ;ToolTip, %UpTime%, 1240, 944 ;used to use tooltip, but it was unconforable GuiControl,, MyText, %UpTime% Return
[Edit]
Uptime OSD with an options GUI
Ive studiet the GUI section in the help file, so, ive added an options gui to the script, that lets you select colour, font size, wheter to display seconds or not, its position, and wether to display it or not.
the home edition goes as far as 49 days,,
and im currently developing the pro edition, ( free once it's out of corse :wink: )
; AutoHotkey ; Language: English ; Platform: Xp pro sp2 ; Author: Leo.U @ [email protected] ; Script Function: Leo's Uptime Display #SingleInstance force ;----- define some scipt options ConfigTitle = Leos Uptime (Home edition) V 2.2 ; ;there is a problem if you want to place an ini file in an non existing directory ; so you first have to create the directory for it to work, ConfigDirectory = Configs\ ; leave it blank if you want it in the script directory and don't forget the "\" at the end if you do. ConfigFileName = Leos_UT_config.ini FullConfigFilePath = %ConfigDirectory%%ConfigFileName% ;-------------Load Settings from Config ini,if not exits, then create default values IfNotExist, %FullConfigFilePath% ;if config is blank, write defaut values. Gosub, SetAllConfigValuesToDefault Gosub, ReadAllConfigSettings If UpTime_Enabled { GoSub, MyUptimeguiOSD ; Gui bit of the OSD Gosub, UpTimeTimer ;display straight away the initial values. If UpTime_DisplaySeconds SetTimer, UpTimeTimer , 1000, -50 ;the timer keeps refreshing the time Else SetTimer, UpTimeTimer , 60000, -50 } ;----Set up Tray ;Menu, TRAY, Icon, Resources\Icons\EyeOfTheSunIcon.ico ; edit it to make your own icon Menu, tray, NoStandard menu, tray, add, &Reload scipt, ReloadScript menu, tray, add, P&ause Script, PauseScript menu, tray, add, &Configurations, ShowOptionsGUI menu, tray, add, &Exit Leos keys, ExitScipt Return ;==============================End of the autload section======================= ;=============================================================================== ;-----------------Tray Menu Items ShowOptionsGUI: Gosub, InitilizeGUI Return ReloadScript: Reload ;a return isnt neccessary .... ExitScipt: ExitApp ; a return isnt neccessary .... Return PauseScript: Pause, Toggle Return ;F1::Reload ;Esc::ExitApp ;#q::WinGetActiveTitle, CurrentWinName ;#w::Send, %CurrentWinName% ReadAllConfigSettings: IniRead, UpTime_Enabled, %FullConfigFilePath%, UpTimeDisplayOptions, Enabled, Default IniRead, UpTime_DisplaySeconds, %FullConfigFilePath%, UpTimeDisplayOptions, DisplaySeconds, Default IniRead, UpTime_FontColour, %FullConfigFilePath%, UpTimeDisplayOptions, Color, Default IniRead, UpTimer_Position, %FullConfigFilePath%, UpTimeDisplayOptions, Position IniRead, UpTimer_FontSize, %FullConfigFilePath%, UpTimeDisplayOptions, FontSize Return SetAllConfigValuesToDefault: FileCreateDir, %ConfigDirectory% IniWrite, 1, %FullConfigFilePath%, UpTimeDisplayOptions, Enabled IniWrite, 0, %FullConfigFilePath%, UpTimeDisplayOptions, DisplaySeconds IniWrite, Lime, %FullConfigFilePath%, UpTimeDisplayOptions, Color IniWrite, Bottom Right, %FullConfigFilePath%, UpTimeDisplayOptions, Position IniWrite, 20, %FullConfigFilePath%, UpTimeDisplayOptions, FontSize Return InitilizeGUI: IfWinExist, %ConfigTitle% { Gui, Show,, %ConfigTitle% Return } IfNotExist, %FullConfigFilePath% ;if config is blank, write defaut values. Gosub, SetAllConfigValuesToDefault Gosub, ReadAllConfigSettings Gui, +AlwaysOnTop +Owner Gui, Add, Tab,, Up Time|Credits ;----------------------------------- Gui, Tab, Up Time ; Ini Section UpTimeDisplayOptions Gui, Add, Checkbox, Checked%UpTime_Enabled% vUpTime_EnabledUpdate, Show Uptime Display ;Key: Enabled /var:UtCbDisplay ;Key DisplaySeconds/ Var:UpTime_DisplaySeconds Gui, Add, Checkbox, Checked%UpTime_DisplaySeconds% vUpTime_DisplaySecondsUpdate, Display Seconds Gui, Add, Text,, Timer Color? ;Key: color/ Var: UpTimeCurrentFontColour Gui, Add, ComboBox, vUpTime_FontColourUpdate xp+80,%UpTime_FontColour%|| |Black|Silver|Gray|White|Maroon|Red|Purple|Fuchsia|Green|Lime|Olive|Yellow|Navy|Blue|Teal|Aqua Gui, Add, Text,xp-80 yp+23, Timer Position? ;Key: Position /Var:UpTimerPosition Gui, Add, ComboBox, vUpTimer_PositionUpdate xp+80 W150, %UpTimer_Position%|| |Bottom Right|Bottom Left|Top Right|Top Left Gui, Add, Text, yp+23 xp-80, Size: Gui, Add, ComboBox, vUpTimer_FontSizeUpdate xp+80,%UpTimer_FontSize%|| |4|5|6|7|8|9|10|11|13|15|17|20|22|25|27|30|35 ;------------------------------------ Gui, Tab, Credits ; well, about me really. Gui, Add, Text,, Designed and written by leo, `n if you find a major bug, or if you can `n suggest any improvements`n please mail me at:`n [email protected] `n`nHappy uptiming :-) ;Gui, Add, Edit, vMyEdit r5 ; r5 means 5 rows tall. Gui, Tab ; i.e. subsequently-added controls will not belong to the tab control. Gui, Add, Button, default xm gGUIApplyChanges, Apply ; xm puts it at the bottom left corner. Gui, Add, Button, default xp+50 gGUIButtonReload, Apply and Reload ; xm puts it at the bottom left corner. Gui, Add, Button, xp+100, Cancel ; xm puts it at the bottom left corner. Gui, Show,, %ConfigTitle% return GUIApplyChanges: Gui, Submit ; Save each control's contents to its associated variable. ;MsgBox You entered:`n display uptime? %MyCheckbox% ; `n%MyRadio%`n%MyEdit% UtCbDisplay = %MyCheckbox% ;----- Uptime TAB Write statement: if any option changed, then rewrite the lot. If ( (UpTime_Enabled != UpTime_EnabledUpdate) OR (UpTime_DisplaySeconds != UpTime_DisplaySecondsUpdate) OR (UpTime_FontColour != UpTime_FontColourUpdate)OR (UpTimer_Position != UpTimer_PositionUpdate) OR (UpTimer_FontSizeUpdate != UpTimer_FontSize) ) { IniWrite, %UpTime_EnabledUpdate%, %FullConfigFilePath%, UpTimeDisplayOptions, Enabled IniWrite, %UpTime_DisplaySecondsUpdate%, %FullConfigFilePath%, UpTimeDisplayOptions, DisplaySeconds IniWrite, %UpTime_FontColourUpdate%, %FullConfigFilePath%, UpTimeDisplayOptions, color IniWrite, %UpTimer_PositionUpdate%, %FullConfigFilePath%, UpTimeDisplayOptions, Position IniWrite, %UpTimer_FontSizeUpdate%, %FullConfigFilePath%, UpTimeDisplayOptions, FontSize } gui, Destroy Return GUIButtonReload: Gosub, GUIApplyChanges Reload Return GuiClose: GuiEscape: ButtonCancel: gui, Destroy Return ;================================ODS UpTime display================================================== ;==================================================================================================== ;SetTimer, UpTimeTimer , 1000 ;these 2 serve the purpose of uptime < put in autoexecution section> ;GoSub, MyUptimeguiOSD ; Gui bit of the OSD MyUptimeguiOSD: ; make sure to have this either in the auto execution section or as a gosub.(GoSub, MyUptimeguiOSD) If UpTime_FontColour != OSDUptimeColour = %UpTime_FontColour% Else OSDUptimeColour = Lime If UpTimer_FontSize != OSDUptimeSize = %UpTimer_FontSize% Else OSDUptimeSize = 20 ;------------Postion If UpTimer_Position = Bottom Right { OSDUptimePosX := A_ScreenWidth - 180 ;this and the below bit makes sure it works on every pc OSDUptimePosY := A_ScreenHeight - 104 ; by adjusting the postion of the OSD of the current screen res. } Else If UpTimer_Position = Bottom Left { OSDUptimePosX = 10 ;this and the below bit makes sure it works on every pc OSDUptimePosY := A_ScreenHeight - 104 ; by adjusting the postion of the OSD of the current screen res. } Else If UpTimer_Position = Top Right { OSDUptimePosX := A_ScreenWidth - 180 ;this and the below bit makes sure it works on every pc OSDUptimePosY = 10 ; by adjusting the postion of the OSD of the current screen res. } Else if UpTimer_Position = Top Left { OSDUptimePosX = 50 ;this and the below bit makes sure it works on every pc OSDUptimePosY = 10 ; by adjusting the postion of the OSD of the current screen res. } CustomColor = EEAA99 ; Can be any RGB color (it will be made transparent below). Gui, 2:+AlwaysOnTop +LastFound +Owner ; +Owner prevents a taskbar button from appearing. Gui, 2:Color, %CustomColor% Gui, 2:Font, s%OSDUptimeSize% Gui, 2:Add, Text, vMyText c%OSDUptimeColour% , XXXXX YYYYY ; XX & YY serve to auto-size the window. ; Make all pixels of this color transparent and make the text itself translucent (150): WinSet, TransColor, %CustomColor% 150 Gui, 2:-Caption ; Remove the title bar and window borders. GuiControl, 2:, MyText, %UpTime% ; < this was in the timer (got moved to my one) Gui, 2: Show, x%OSDUptimePosX% y%OSDUptimePosY% return UpTimeTimer: ; ToTal*unit*, "//"" gets rid of the uneccessary decimals ;*for use in the next bit. TTMilliseconds := A_TickCount TTSeconds := A_TickCount // 1000 ;*1000 Mil secs in a second TTMinutes := A_TickCount // 60000 ; *60 secs in an minute TTHours := A_TickCount // 3600000 ; *60 Mins in an hour TTDays := A_TickCount // 86400000 ; *24 hours in a day TTWeeks := A_TickCount // 604800000 ; *52 weeks in a year. ;-) ; This bit works out the exact timing. an example would be,, you cant display 700 Totatl ; Mintues, so you work out the unneccessary 11 hours (11 * 60 = 660) ; and take them of the total 700 - 660 = 40 Minutes. And you got what you want. UpMilliseconds := TTMilliseconds - (1000 * (TTMilliseconds // 1000)) UpSeconds := TTSeconds - (60 * (TTSeconds // 60)) UpMinutes := TTMinutes - (60 * (TTMinutes // 60)) UpHours := TTHours - (24 * (TTHours // 24)) UpDays := TTDays - (7 * (TTDays // 7)) UpWeeks := TTWeeks - (52 * (TTWeeks // 52)) ;This is for determination of wheter or not the ":" Colon and time digits should be displayed, ;(other wise it'll show some thing like 00:00:3:2:42:5 instead of 03:02:42:05) ;AutoTrim, off If UpWeeks >= 1 Wc := FnUpTimeCharSetFormat(UpWeeks) ;Wc as in Weeks coloums If UpDays >= 1 Dc := FnUpTimeCharSetFormat(UpDays) If UpHours >= 1 Hc := FnUpTimeCharSetFormat(UpHours) If UpMinutes >= 1 Mc = %UpMinutes% If UpTime_DisplaySeconds { If UpSeconds = 0 Sc = :00 Else If UpSeconds <= 9 Sc = :0%Upseconds% Else if UpSeconds >= 10 Sc = :%UpSeconds% } UpTime = %Wc%%Dc%%Hc%%Mc%%Sc% ;%UpSeconds% ;:%Milliseconds% ;its upto you to include Mili secs, i dont like them. GuiControl, 2:, MyText, %UpTime% Return FnUpTimeCharSetFormat(Input) { If input <= 9 Input = 0%Input% if Input >=1 Input = %Input%: Else Return Return Input }