Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Countdown timer app


  • Please log in to reply
18 replies to this topic
bekihito
  • Members
  • 42 posts
  • Last active: Sep 04 2013 07:33 PM
  • Joined: 03 Feb 2010
Hi everybody,
recently I'm having a lot of free time while on work so I keep looking at my watch and calculate how much longer I have to stay there before I go home.
Therefore I searched a few older treads on Countdown timers and this is the result:
/*
Countdown 1.0 aka How long till I go home?
by Bekihito, WTFPL licence (http://en.wikipedia.org/wiki/WTFPL)
many thanks to the authors  and contributors of http://www.autohotkey.com/forum/viewtopic.php?t=19740&highlight=countdown
for inspiration and help with this variant
*/

SetBatchLines, -1
#SingleInstance, Force
#NoEnv
SetWorkingDir , %A_ScriptDir%
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

if (FileExist("CountSet.ini")){
    IniRead , XPos, CountSet.ini, Position, XPosition, 
    IniRead , YPos, CountSet.ini, Position, YPosition, 
    IniRead , Message, CountSet.ini, User, Message
    IniRead , StartTime, CountSet.ini, User, StartTime
    IniRead , EndTime, CountSet.ini, User, EndTime
    }Else{
        XPos := XI/2
        YPOs := YI/2
        Message = "Time to go!!!"
    }

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)
CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, NoStandard
Menu,Tray, Add, EndTime, SetClock
Menu,Tray, Add, Period, SetPeriod
Menu,Tray, Add,
Menu,Tray, Add, Message, SetMessage
Menu,Tray, Add, 
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress 
Gui, Font, s16 
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00 
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):

SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.

Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

Return  ; // End of Auto-Execute Section


UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    MsgBox,,Done, %Message%
    }
Return

SetClock: ;Input the goal time -in my case the time I get of work,but you could type e.g. X-mass
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox , Date, Set Date ,YYYYMMDD,,160,120, %XInput%, %YInput%,,, %A_YEAR%%A_MM%%A_DD%
InputBox ,Goal ,Set EndTime,HHmm,,160 ,120, %XInput%, %YInput%,,,HHmm
Emsec = 00
StartTime = %A_Now%
EndTime = %Date%%Goal%%Emsec%
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetPeriod: ; Input any given time period like DDDHHmm = 0010101 = 1day 1hour 1minutes for fancy egg timer function
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox ,Period ,Set Period,DDDHHmm,,160 ,120, %XInput%, %YInput%,,,DDDHHmm
StringMid ,PeriodD, Period,1, 3
StringMid ,PeriodH, Period,4, 2
StringMid ,Periodm, Period,6, 2
Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
StartTime = %A_Now%
EndTime = %A_Now%
EnvAdd EndTime, Periodsec, seconds
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetMessage: ;Input custom message that will popup when the timer gets to 00:00:00
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
InputBox ,Message, Set Message, Custom message: ,,160 ,120, %XInput%, %YInput%,,,%Message%
Return

GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
WinGetPos ,XPos ,YPos,,,Time-to-Go
IniWrite , %XPos%, %A_ScriptDir%\CountSet.ini, Position, XPosition
IniWrite , %YPos%, %A_ScriptDir%\CountSet.ini, Position, YPosition
IniWrite , %Message%, %A_ScriptDir%\CountSet.ini, User, Message
IniWrite , %StartTime%, %A_ScriptDir%\CountSet.ini, User, StartTime
IniWrite , %EndTime%, %A_ScriptDir%\CountSet.ini, User, EndTime
ExitApp

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss 
}
Hope you like it!

Bebert
  • Members
  • 84 posts
  • Last active: Jan 03 2011 06:47 AM
  • Joined: 08 Jun 2009
neat little timer with resume after close, many thanks will be very handy!

one question about modding - how to add buttons for start/end time on the main GUI instead of the tray menu?

merci :)

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
Here is a much more direct way to put seconds in h:mm:ss format
FormatSeconds(x) 

{ 

Loop 2 ;make it base 60 with : divider Sec and Min

  Out:=SubStr("0" . Mod(x, 60),-1) ":" Out,x:=Floor(x/60)

Out:=x ":" Out ;put hours on front

Return SubStr(Out,1,-1) ;remove extra : 

}
Will still work if you put in 1000 hours worth of seconds

bekihito
  • Members
  • 42 posts
  • Last active: Sep 04 2013 07:33 PM
  • Joined: 03 Feb 2010

neat little timer with resume after close, many thanks will be very handy!

one question about modding - how to add buttons for start/end time on the main GUI instead of the tray menu?

merci :)

I'm glad you like it. If you wish to have the menu items inside the window add this piece of code after the Tray menu lines (around line 38 or anywhere before GUI, Show)
;To Place a Menu bar with options into the window
Menu,Settings, Add, EndTime, SetClock
Menu,Settings, Add, Period, SetPeriod
Menu,Settings, Add, Message, SetMessage
Menu, Bar, Add, Set, :Settings
Menu,Bar, Add, Exit, GuiClose
;Menu,Bar, Color, %CustomColor% ;uncomment if you wish to have the same transparency look and feel, but less viewable
Gui , Menu, Bar
Or if you want something else check the Menu command in the documentation.
However, I leave up to you to place the Input boxes (where they popup ) in a better place ;-). Now they are (more or less) near the Tray icon.

To @none: I know that perhaps there are better ways to do this entirely, but as I stated in the precomment it is a product of few older treads (specifically the part of code you mention is from the AHK documentation FORMATTIME examples) but feel free to improve/change anything.
BR

Bebert
  • Members
  • 84 posts
  • Last active: Jan 03 2011 06:47 AM
  • Joined: 08 Jun 2009
thanks bekihito.

I actually made a couple of main GUI buttons with gEndTime and gPeriod - works also.

poserpro
  • Guests
  • Last active:
  • Joined: --
Greetings,
I want the counter to plan a sound to remind me, so i modified the code as :

/*
Countdown 1.0 aka How long till I go home?
by Bekihito, WTFPL licence (http://en.wikipedia.org/wiki/WTFPL)
many thanks to the authors  and contributors of http://www.autohotkey.com/forum/viewtopic.php?t=19740&highlight=countdown
for inspiration and help with this variant
*/

SetBatchLines, -1
#SingleInstance, Force
#NoEnv
SetWorkingDir , %A_ScriptDir%
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

if (FileExist("CountSet.ini")){
    IniRead , XPos, CountSet.ini, Position, XPosition,
    IniRead , YPos, CountSet.ini, Position, YPosition,
    IniRead , Message, CountSet.ini, User, Message
    IniRead , StartTime, CountSet.ini, User, StartTime
    IniRead , EndTime, CountSet.ini, User, EndTime
    }Else{
        XPos := XI/2
        YPOs := YI/2
        Message = "Time to go!!!"
    }

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)
CustomColor = C0C0C0 ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, NoStandard
Menu,Tray, Add, EndTime, SetClock
Menu,Tray, Add, Period, SetPeriod
Menu,Tray, Add,
Menu,Tray, Add, Message, SetMessage
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):

SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.

Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

Return  ; // End of Auto-Execute Section


UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    SoundPlay, d:\frantic.wav
    ;sgBox,,Done, %Message%
    }
Return

SetClock: ;Input the goal time -in my case the time I get of work,but you could type e.g. X-mass
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox , Date, Set Date ,YYYYMMDD,,160,120, %XInput%, %YInput%,,, %A_YEAR%%A_MM%%A_DD%
InputBox ,Goal ,Set EndTime,HHmm,,160 ,120, %XInput%, %YInput%,,,HHmm
Emsec = 00
StartTime = %A_Now%
EndTime = %Date%%Goal%%Emsec%
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetPeriod: ; Input any given time period like DDDHHmm = 0010101 = 1day 1hour 1minutes for fancy egg timer function
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
WinGetPos ,XPos ,YPos,,,Time-to-Go,
InputBox ,Period ,Set Period,DDDHHmm,,160 ,120, %XInput%, %YInput%,,,DDDHHmm
StringMid ,PeriodD, Period,1, 3
StringMid ,PeriodH, Period,4, 2
StringMid ,Periodm, Period,6, 2
Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
StartTime = %A_Now%
EndTime = %A_Now%
EnvAdd EndTime, Periodsec, seconds
EnvSub StartTime, EndTime, seconds
StartTime := Abs(StartTime)
Goto, UpdateOSD

SetMessage: ;Input custom message that will popup when the timer gets to 00:00:00
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
InputBox ,Message, Set Message, Custom message: ,,160 ,120, %XInput%, %YInput%,,,%Message%
Return

GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
WinGetPos ,XPos ,YPos,,,Time-to-Go
IniWrite , %XPos%, %A_ScriptDir%\CountSet.ini, Position, XPosition
IniWrite , %YPos%, %A_ScriptDir%\CountSet.ini, Position, YPosition
IniWrite , %Message%, %A_ScriptDir%\CountSet.ini, User, Message
IniWrite , %StartTime%, %A_ScriptDir%\CountSet.ini, User, StartTime
IniWrite , %EndTime%, %A_ScriptDir%\CountSet.ini, User, EndTime
ExitApp

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}

This works for me. You can customize the wav sound as a crazy woman/man scream or a simple ring tone, or a beep or likewise.

Cheers
-pop

mrr19121970
  • Members
  • 29 posts
  • Last active: Dec 12 2010 09:55 AM
  • Joined: 30 Apr 2009
Here's my contribution based on tic's GDI+

#SingleInstance,Ignore
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

	DetectHiddenWindows On
	
; Start gdi+
	If !pToken := Gdip_Startup()
	{
	   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
	   GoSub,GUIClose
	}

;---------------------------------------

	Menu,Tray,NoStandard
	Menu,Tray,DeleteAll
	Menu,Tray,Add,Exit,GuiClose

;Change this based on when you want to countdown to
	EndTime := 20101228140000

	Font = Arial
	Size = 36
	Style = Regular
	SAlign = Left
	SvPos = Bottom
	Transparancy = 255
	Vtolerance = -30
	Htolerance = 0
	Colour = ffffff
	Border = 3
	BColour = 000000

	Settimer,Preview_PNG,1000

Return

;---------------------------------------

GUIClose:

; gdi+ may now be shutdown on exiting the program
	Gdip_Shutdown(pToken)
	
	ExitApp

Return

;---------------------------------------

Preview_PNG:

	mysec := EndTime
	EnvSub, mysec, %A_Now%, seconds

	if mysec < 7200
		Colour = ffff00
	if mysec < 3600
		Colour = ff0000
	if mysec < 0
		GoSub,GUIClose
		
	Text = % "Countdown : " . FormatSeconds( mysec )

;-- Build temporary window to determine maximum width
	Gui 3:-Caption
	gui 3:Margin,0,0
	gui 3:Font,s%Size%,%Font%
	gui 3:Add,Text,,%Text%
	gui 3:Show,Hide  ;-- Render but don't show	

;-- How wide is it?
	gui 3:+LastFound
	WinGetPos ,,,Width,Height,% "ahk_id " . WinExist()
	gui 3:Destroy
	
; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
	Gui, 4: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
	Gui, 4: Show, NA

; Get a handle to this window we have created in order to update it later
	hwnd1 := WinExist()

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
	hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)

; Get a device context compatible with the screen
	hdc := CreateCompatibleDC()

; Select the bitmap into the device context
	obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
	G := Gdip_GraphicsFromHDC(hdc)

; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
	Gdip_SetSmoothingMode(G, 4)

	WriteText(G, Text, Size, Align, vPos, Font, Colour, Transparancy, Style, Border, BColour,  Width, Height)

	if SAlign = Left
	{
		TextToImage_X := 0 + Htolerance
	}
	if SAlign = Centre
	{
		TextToImage_X := ((A_ScreenWidth - Width) // 2) + Htolerance
	}
	if SAlign = Right
	{
		TextToImage_X := A_ScreenWidth - Width + Htolerance
	}
	if SvPos = Top
	{
		TextToImage_Y := 0 + Vtolerance
	}
	if SvPos = vCentre
	{
		TextToImage_Y := ((A_ScreenHeight - Height) // 2) + Vtolerance
	}
	if SvPos = Bottom
	{
		TextToImage_Y := A_ScreenHeight - Height + Vtolerance
	}

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier
	UpdateLayeredWindow(hwnd1, hdc, TextToImage_X, TextToImage_Y, Width, Height)

; Select the object back into the hdc
	SelectObject(hdc, obm)

; Now the bitmap may be deleted
	DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
	DeleteDC(hdc)

Return

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
	FormatTime, mm, %time%, mm
	FormatTime, ss, %time%, ss
	days := NumberOfSeconds // (3600 * 24)
	hours := (NumberOfSeconds // 3600) - (days * 24)
    return days " days, " hours " hours, " mm " minutes, " ss " seconds"
}

WriteText(G="", Text="TextToImage", Size="20", Align="Bottom|Centre", vPos="Top", Font="Arial", Colour="ffffff", Transparancy="ff", Style="", Border="0", BColour="000000",  Width="", Height="")
{
	SetFormat, integer, hex
	Transparancy := Transparancy
	SetFormat, integer, d

	Gdip_GraphicsClear(G, 0x00ffffff)
	Gdip_SetInterpolationMode(G,7)	
	pPath := Gdip_CreatePath(0)
	Options = w%Width% h%Height% %Align% s%Size% %Style%
	Gdip_AddString(pPath, Text, Font, Options)
	if Border > 0
	{
		pPen := Gdip_CreatePen(Transparancy . BColour, Border)
		Gdip_SetLineJoin(pPen)
		Gdip_DrawPath(G, pPen, pPath)
		Gdip_DeletePen(pPen)
	}
	pBrush := Gdip_BrushCreateSolid(Transparancy . Colour)
	Gdip_FillPath(G, pBrush, pPath)
	Gdip_DeleteBrush(pBrush)
	Gdip_DeletePath(pPath)
}

Gdip_AddString(Path, sString,fontName, options,stringFormat=0x4000)
{
   nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
   VarSetCapacity(wString, nSize*2)
   DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)

	hFamily := Gdip_FontFamilyCreate(fontName)
	RegExMatch(Options, "i)X([\-0-9]+)", xpos)
	RegExMatch(Options, "i)Y([\-0-9]+)", ypos)
	RegExMatch(Options, "i)W([0-9]+)", Width)
	RegExMatch(Options, "i)H([0-9]+)", Height)
	RegExMatch(Options, "i)R([0-9])", Rendering)	
		
	Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
	Loop, Parse, Styles, |
	{
		If RegExMatch(Options, "i)\b" A_loopField)
		Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
	}
	RegExMatch(Options, "i)S([0-9]+)", fontSize)
	Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
	Loop, Parse, Alignments, |
	{
		If RegExMatch(Options, "i)\b" A_loopField)
		Align |= A_Index//2.1      ; 0|0|1|1|2|2
	}
	hFormat := Gdip_StringFormatCreate(stringFormat)
	Gdip_SetStringFormatAlign(hFormat, Align)	
	Gdip_SetTextRenderingHint(pGraphics, Rendering)
	CreateRectF(textbox, xpos1, ypos1, Width1, Height1)	
	iRet := DllCall("gdiplus\GdipAddPathString", "UInt", Path,  "UInt", &wString, "Int", -1, "Uint",hFamily, "Int", Style, "Float", fontSize1,"UInt", &textbox, "UInt", hFormat)
	Gdip_DeleteFontFamily(hFamily)
	Gdip_DeleteStringFormat(hFormat)
	return iRet 			
}

Gdip_DrawPath(pGraphics, pPen, Path)
{
	return DllCall("gdiplus\GdipDrawPath", "UInt", pGraphics, "UInt", pPen, "UInt", Path)
}

Gdip_SetLineJoin(pPen, linejoin=2) ;LineJoinMiter = 0,LineJoinBevel = 1,LineJoinRound = 2,LineJoinMiterClipped = 3
{
	return DllCall("gdiplus\GdipSetPenLineJoin", "Uint", pPen, "uInt", linejoin)
}



BeauC
  • Members
  • 1 posts
  • Last active: Feb 26 2011 11:07 PM
  • Joined: 30 Dec 2010
This script is very close to what I have been looking for. I have been able to modify it to suit my needes except for one thing. I am unable to run it in conjunction with I have been writing.

I have a script that I am writing where I use a loop to one-by-one connect to a remote computer with a program, download some log files and do some file moving. The reason I am looking for a timer is that the download time for the logs can take about 5-10 minutes and it would be nice to display this to the end user.

I don't have the exact code with me (it's on my work computer), but what I have looks something like:

-Start loop
-Open My program
-Do some repetitive keypresses/mous clicks to start log download
*START TIMER W/ GUI HERE
-Wait for 5 minutes
-When timer is done carry on with the next instance of the loop, rinse and repeat

Is there some way for this script to be integrated (function calls are something)?

EDIT:

Figured it out. For anyone who wants to modify this script to control the timing of a loop, see code below.

I removed the need for an ini file, gave a static Period (didn't need a clock feature), closed the GUI when not actively counting. It is a little resource intense, but works well enough for my needs.
XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

XPos := XI/2
YPOs := YI/2
Message = "Log download complete"

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)


CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, Add
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00


Loop, 3
{
    MsgBox, Iteration number is %A_Index%.  ; A_Index will be 1, 2, then 3
    Sleep, 1000

	SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
	Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

	Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
	WinGetPos ,XPos ,YPos,,,Time-to-Go,
	Period = 0000001 ;Specified a known static Period (1 minute for testing purposes
	StringMid ,PeriodD, Period,1, 3
	StringMid ,PeriodH, Period,4, 2
	StringMid ,Periodm, Period,6, 2
	Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
	StartTime = %A_Now%
	EndTime = %A_Now%
	EnvAdd EndTime, Periodsec, seconds
	EnvSub StartTime, EndTime, seconds
	StartTime := Abs(StartTime)

	perc := 0 ;Resets percentage to 0, otherwise this loop never sees the counter reset
	Loop
	{
	    if perc = 100
	        break  ; Terminate the loop
	    else
	        continue ; Skip the below and start a new iteration
	}
    MsgBox, Loop %A_Index% is ended
    Gui, Cancel
}

UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    Gui, Cancel
    }
Return


GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
ExitApp


FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}



Error404
  • Members
  • 3 posts
  • Last active: Sep 01 2011 02:34 PM
  • Joined: 14 Apr 2011
Sweeet 8)

NAVEEN KUMAR
  • Guests
  • Last active:
  • Joined: --
hello

for me when i compile this file, a window is showing with list of errors and saying that the thread will be exitted, but the code is still running and when i right click on the Hky icon is is asking start time, end time message etc, where can i see how many minutes elapsed etc.. is there something wrong with my installation?

can u help me out from this.

bekihito
  • Members
  • 42 posts
  • Last active: Sep 04 2013 07:33 PM
  • Joined: 03 Feb 2010
dear naveen kumar,
are you using the new AHK_L or vanila AHK - it is made for vanila AHK.
here is the precompiled version that works fine on my XPSP3 and WIN7 computers:
https://ahknet.autoh...n/Countdown.exe
BR

bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

This script is very close to what I have been looking for. I have been able to modify it to suit my needes except for one thing. I am unable to run it in conjunction with I have been writing.

I have a script that I am writing where I use a loop to one-by-one connect to a remote computer with a program, download some log files and do some file moving. The reason I am looking for a timer is that the download time for the logs can take about 5-10 minutes and it would be nice to display this to the end user.

I don't have the exact code with me (it's on my work computer), but what I have looks something like:

-Start loop
-Open My program
-Do some repetitive keypresses/mous clicks to start log download
*START TIMER W/ GUI HERE
-Wait for 5 minutes
-When timer is done carry on with the next instance of the loop, rinse and repeat

Is there some way for this script to be integrated (function calls are something)?

EDIT:

Figured it out. For anyone who wants to modify this script to control the timing of a loop, see code below.

I removed the need for an ini file, gave a static Period (didn't need a clock feature), closed the GUI when not actively counting. It is a little resource intense, but works well enough for my needs.

XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

XPos := XI/2
YPOs := YI/2
Message = "Log download complete"

XInput := XI-250
YInput := YI-150
;On-screen display (OSD)


CustomColor = 99AA55  ; Can be any RGB color (it will be made transparent below).
Menu ,Tray, Add
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00


Loop, 3
{
    MsgBox, Iteration number is %A_Index%.  ; A_Index will be 1, 2, then 3
    Sleep, 1000

	SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
	Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

	Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
	WinGetPos ,XPos ,YPos,,,Time-to-Go,
	Period = 0000001 ;Specified a known static Period (1 minute for testing purposes
	StringMid ,PeriodD, Period,1, 3
	StringMid ,PeriodH, Period,4, 2
	StringMid ,Periodm, Period,6, 2
	Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)
	StartTime = %A_Now%
	EndTime = %A_Now%
	EnvAdd EndTime, Periodsec, seconds
	EnvSub StartTime, EndTime, seconds
	StartTime := Abs(StartTime)

	perc := 0 ;Resets percentage to 0, otherwise this loop never sees the counter reset
	Loop
	{
	    if perc = 100
	        break  ; Terminate the loop
	    else
	        continue ; Skip the below and start a new iteration
	}
    MsgBox, Loop %A_Index% is ended
    Gui, Cancel
}

UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    Gui, Cancel
    }
Return


GuiClose: ;writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the comp)
ExitApp


FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}

Excellent script! I edited the part high-lighted in blue to allow static periods for seconds: :lol:
; http://www.autohotkey.com/community/viewtopic.php?f=2&t=62008

XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

XPos := XI/2
YPOs := YI/2
Message = "Log download complete"

XInput := XI-250
YInput := YI-150
; On-screen display (OSD)


CustomColor = 99AA55 ; C0C0C0 ; Can be any RGB color (it will be made transparent below):
Menu ,Tray, NoStandard
;Menu ,Tray, Add
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
Gui Add , Text , x0 y10  w130 h15 vpercent +Center, Time elapsed %perc% `%
Gui Add , Progress , x5 y30 w120 h10 cRed  vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):
/*
SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.
Return  ; // End of Auto-Execute Section
*/

Loop, 1 ; 3
{
    ; MsgBox, Iteration number is %A_Index%.  ; A_Index will be 1, 2, then 3
    Sleep, 100 ; 1000

   SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
   Gui, Show, x%XPos% y%YPos% w130 NoActivate, Time-to-Go ; NoActivate avoids deactivating the currently active window.

   Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
   WinGetPos ,XPos ,YPos,,,Time-to-Go,
   ;Period = 0000001 ; Specified a known static Period (1 minute for testing purposes)
[color=#0000FF]   Period = 00000015 ; Specified a known static Period (15 seconds for testing purposes)
   StringMid ,PeriodD, Period,1, 2
   StringMid ,PeriodH, Period,3, 2
   StringMid ,Periodm, Period,5, 2
   StringMid ,Periods, Period,7, 2
   Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)+Periods[/color]
   StartTime = %A_Now%
   ;EndTime = %A_Now%
   ;EndTime = 20121021181050
   EnvAdd EndTime, Periodsec, seconds
   EnvSub StartTime, EndTime, seconds
   StartTime := Abs(StartTime)

   perc := 0 ; Resets percentage to 0, otherwise this loop never sees the counter reset
   Loop
   {
       if perc = 100
           break  ; Terminate the loop
       else
           continue ; Skip the below and start a new iteration
   }
    ; MsgBox, Loop %A_Index% is ended
    MsgBox, Run Application-1!
    Gui, Cancel
    ExitApp
}

UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
perc := Floor(perc)
GuiControl ,,myprogress,%perc%
GuiControl ,,percent, Time elapsed %perc% `%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    Gui, Cancel
    }
Return

GuiClose: ; writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you 

had to shutdown the computer)
ExitApp

FormatSeconds(NumberOfSeconds)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    time = 19990101  ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections.
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}


MrSharkDog
  • Members
  • 1 posts
  • Last active: Oct 20 2013 03:19 AM
  • Joined: 10 Apr 2013

Hi all i've been searching for a timer that counts down from a set time to 0 and playing a .wav file when finished.. and some want to be set times other to be a time i can change in the program and starting the countdown by hitting a hotkey like ctrl + 1 or something whilst being active in another program....

 

 

 

as i see here in your explanations and codes i can decifer a little bit with my common sense and understanding of this for me old knowledge is that some could come in handy to use as a base for me to make / design my own one as how i want it to work / be..

 

when i made a website for my company i used old skool note pad style.. and just put the ext to .html.. the writing took me a week to figure out how the codes worked again but i managed... and the site came out very nice.. untill my company was run to the ground so no need for that nomore.. but i was proud of myself.. making it that profesional just by entering / writing and re-understanding the codes as i went on creating and building the site.. it was a challenge for me to remember and learn again how it worked.... and not using any site builder or sorts because that wasn't a challenge...

 

I want to use it for a txt based game that im playing... wich involves upgrading things and than it countsdown before you can create something new and those sort of things... but the thing is.. the last time i made a program was about 15 years ago @ school.. and learned only the basics at that time.. and my knowledge is a bit rusty.. 

 

so can anyone help me out with these basic questions ?



Fredor
  • Members
  • 1 posts
  • Last active: Mar 02 2015 03:36 PM
  • Joined: 16 Oct 2013

This script does nothing at all!

It only shows a box with 6 red zeros, "time elapsed 0%" and nothing else. The script has no explanation inside.

What do i have to modify to use the timer?



Travler_III
  • Members
  • 2 posts
  • Last active: Nov 08 2013 08:32 AM
  • Joined: 06 Nov 2013

Could anyone help me?
i'm actually the noobest person if it's about scripting.

i'm playing a game (SMITE) where i could need 6 countdowntimers that start when i pres f1 for the first one, f2 for the second one,...
also i wan't it to be visual in my screen when i press taht key? kan anyone help me PLS?