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 

Yet Another CountDown Script

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Sat Jul 21, 2007 11:59 pm    Post subject: Yet Another CountDown Script Reply with quote

Browsing the forum I found several countdown scripts.
But as usual I made my own solution that fully satisfies my needs.

The main adventages of this script are:
  • Specify sound file to be played on end of countdown
  • Counting can be tracked on taskbar button's text
  • Stop countdown without restarting the script
  • Settings stored in INI file
  • I provide a nice screenshot Razz




And here is the code:
Code:
; CountDown.ahk - Countdown timer with sound alert
;
; Simple script that counts down specified number of seconds to zero.
; You can set up a sound file to be played at the end of countdown.
; Settings will be saved to INI file on exit.
;
; You can find the latest version here: http://www.autohotkey.com/forum/viewtopic.php?t=21375
;
; Tested with AutoHotkey 1.0.47.01
;
; Created by HuBa
; Contact: http://www.autohotkey.com/forum/profile.php?mode=viewprofile&u=4693

#SingleInstance Off  ; Allow multiple instances
#NoTrayIcon

cd_IniFile := A_ScriptDir "\CountDown.ini"

; Read settings from INI file
IniRead cd_Duration, %cd_IniFile%, Main, Duration, % 5*60
IniRead cd_PlaySound, %cd_IniFile%, Main, PlaySound, %True%
IniRead cd_SoundFile, %cd_IniFile%, Main, SoundFile, %A_ScriptDir%\

Gui Add, Text, x30 y20 w100 h20, &Hours:
Gui Add, Edit, x90 y18 w80 h20 Number vcd_HoursEdit gTimeEdited, % cd_Duration // 3600
Gui Add, Text, x30 y42 w100 h20, &Minutes:
Gui Add, Edit, x90 y40 w80 h20 Number vcd_MinutesEdit gTimeEdited, % mod(cd_Duration, 3600) // 60
Gui Add, Text, x30 y64 w100 h20, S&econds:
Gui Add, Edit, x90 y62 w80 h20 Number vcd_SecondsEdit gTimeEdited, % mod(cd_Duration, 60)
Gui Add, Text, x30 y86 w210 h20 vcd_DurationText
Gui Add, Checkbox, x30 y111 w200 h30 vcd_PlaySoundCheckBox, &Play sound at the end of countdown
GuiControl,, cd_PlaySoundCheckBox, %cd_PlaySound%
Gui Add, Button, x30 y140 w80 h22 gSoundFileBrowse, Sound &file:
Gui Add, Edit, x30 y164 w200 h20 vcd_SoundFileEdit, %cd_SoundFile%
Gui Add, Button, x180 y140 w50 h22 gPlayFinishSound, &Test
Gui Font, Bold
Gui Add, Button, x30 y200 w200 h30 vcd_Button gCountDownPress Default, &START
Gosub TimeEdited
Gui Show, h250 w260, CountDown
Gui +LastFound
cd_Gui := WinExist()  ; Remember Gui window ID
Return

CountDownPress:
GuiControlGet cd_ButtonCaption,, cd_Button
if cd_ButtonCaption = &STOP  ; Compare button text
{
  SetTimer CountDownTimer, Off
  WinSetTitle ahk_id %cd_Gui%,, CountDown
  GuiControl,, cd_Button, &START
  Return
}
cd_Duration := GetDurationInSec()
if cd_Duration <= 0
{
  MsgBox 16, Error, Invalid time.
  Return
}
WinSetTitle ahk_id %cd_Gui%,, %cd_Duration%  ; Refresh tray button text
GuiControl,, cd_Button, &STOP
SetTimer CountDownTimer, 1000
Return

CountDownTimer:
cd_Duration--
WinSetTitle ahk_id %cd_Gui%,, %cd_Duration%  ; Refresh tray button text
if cd_Duration > 0
  Return
Gui Flash  ; Flash the tray button
GuiControlGet cd_PlaySound,, cd_PlaySoundCheckBox
if cd_PlaySound  ; Play sound if checked
  Gosub PlayFinishSound  ; Let me hear that sound!
Gosub CountDownPress
Return

SoundFileBrowse:
FileSelectFile cd_SoundFile, 1, %cd_SoundFile%  ; Open file selection dialog
if cd_SoundFile
  GuiControl,, cd_SoundFileEdit, %cd_SoundFile%
Return

PlayFinishSound:
GuiControlGet cd_SoundFile,, cd_SoundFileEdit  ; Get filename
IfExist %cd_SoundFile%
  SoundPlay %cd_SoundFile%
Return

TimeEdited:  ; Update duration text
GuiControl,, cd_DurationText, % "Duration: " GetDurationInSec() " seconds"
Return

GetDurationInSec()
{
local Hours, Minutes, Seconds
GuiControlGet Hours,, cd_HoursEdit
GuiControlGet Minutes,, cd_MinutesEdit
GuiControlGet Seconds,, cd_SecondsEdit
Return Hours * 3600 + Minutes * 60 + Seconds
}

GuiClose:  ; Close window, save settings to INI file
GuiControlGet cd_PlaySound,, cd_PlaySoundCheckBox
GuiControlGet cd_SoundFile,, cd_SoundFileEdit
IniWrite % GetDurationInSec(), %cd_IniFile%, Main, Duration
IniWrite %cd_PlaySound%, %cd_IniFile%, Main, PlaySound
IniWrite %cd_SoundFile%, %cd_IniFile%, Main, SoundFile
ExitApp  ; Exit from script
Return


Hope you like it Cool

I updated the script, now the checkbox state is handled correctly.


Last edited by HuBa on Mon Dec 10, 2007 9:13 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
System Monitor



Joined: 09 Mar 2007
Posts: 509
Location: Unknown

PostPosted: Mon Jul 23, 2007 3:43 am    Post subject: Reply with quote

Cool i will probably use this
Back to top
View user's profile Send private message Visit poster's website
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Mon Jul 23, 2007 5:05 am    Post subject: Reply with quote

Here is a cool countdown voice I found on the internet:
http://tinyurl.com/yotayp
Back to top
View user's profile Send private message Visit poster's website
Bytales



Joined: 06 Sep 2008
Posts: 84

PostPosted: Wed Sep 23, 2009 3:45 pm    Post subject: Reply with quote

I like the way you made it. However i need a timer to count forward.
Say a start it now, and it counts the seconds minutes hours days, that have passed.
Further more, and this is the most important thing, i want to be able to resume the count. For instance, i restart windows, start the program, and resume the count.
There has to be a way to make it remember when it started.

I will try to find a way to make this myself, but this seems a rather complicated script for my ahk skills.
Think you can help with this ?
Back to top
View user's profile Send private message
HuBa



Joined: 24 Feb 2007
Posts: 175
Location: Budapest, Hungary

PostPosted: Wed Sep 23, 2009 8:31 pm    Post subject: Reply with quote

Bytales wrote:
I like the way you made it. However i need a timer to count forward.
Say a start it now, and it counts the seconds minutes hours days, that have passed.
Further more, and this is the most important thing, i want to be able to resume the count. For instance, i restart windows, start the program, and resume the count.
There has to be a way to make it remember when it started.

I will try to find a way to make this myself, but this seems a rather complicated script for my ahk skills.
Think you can help with this ?


I think you want to track uptime.
Maybe the A_TickCount variable will help you.
Back to top
View user's profile Send private message Visit poster's website
miagi



Joined: 02 Dec 2009
Posts: 2

PostPosted: Sun Jul 04, 2010 3:55 pm    Post subject: Reply with quote

Thx @HuBa for publishing this great little tool! Very Happy

(I'll be using it to alert me when the building/training/upgrading/... period is over in the "Kingdoms of Camelot" game on Facebook Embarassed )

ps: I got my sound effect here: http://www.a1freesoundeffects.com/freesounds5/cockgun.wav

Oops, I've gotta go! I just heard the sound of a gun cocking! Laughing

Greetings,
Manuel
Back to top
View user's profile Send private message
sumon



Joined: 18 May 2010
Posts: 1016
Location: Sweden

PostPosted: Sun Jul 04, 2010 7:15 pm    Post subject: Reply with quote

Sweeeeeet! Will be used for cooking. Smile I'll try it eventually and get back with results.
Back to top
View user's profile Send private message Visit poster's website
miagi



Joined: 02 Dec 2009
Posts: 2

PostPosted: Mon Jul 05, 2010 12:59 pm    Post subject: Reply with quote

ps: if you want to keep the countdown timer on top you may add the following line of code:

Gui +AlwaysOnTop

(I put it right above "Gui Add, Text, x30 y20 w100 h20, &Hours:")

This is especially usefull if you frequently need to enter new times while you are browsing multiple tabs with firefox in full screen mode... (at least, this is what i'm doing Wink )

Greetings,
Manuel
Back to top
View user's profile Send private message
Rafa30



Joined: 19 Jul 2010
Posts: 2
Location: Acapulco

PostPosted: Tue Jul 20, 2010 2:39 am    Post subject: Ayuda, con el script Reply with quote

are actually four different timers, the note as an example of what made so far, have bugs and I'm interested to run the first example., Thanks

Help: I need Generate a .Ini File at the first time to use the script
Includes a Loop to increase time set in the .Ini or CountDown pressing a key F12 for example and sounplay *.wav
When the countdown show 20 secods, display "Insert Credits"
If counter =00:00 Show "Time Over" and Shutdown Pc
No show the process in Ctrl+Alt+Supr
This Script is for a Internet Kiosk

Problems: Timer is Wrong why time =00:00 non Stop and set the minutes in the actual time

Timer 1
#SingleInstance,Force
#Persistent
#NoTrayIcon

CustomColor = EEAA99
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
Gui, Font, s50 ; Set a large font size (32-point).
Gui, Add, Text, vMyText w300 cred Center,Internet Station
WinSet, TransColor, %CustomColor% 190
Gui, Show, x700 y-10 ,Timer
CountDown= 1800 ; seconds
SomeDate = 16010101
SomeDate += %CountDown%,S
SetTimer NextSecond, 1000
Return

Nextsecond:
SomeDate += -1, seconds
FormatTime formattedTime, %SomeDate%, mm:ss
GuiControl,, MyText, %formattedTime%
Return

F12::
Insert here the Loop to increase the Time


ExitApp

[Deleted double posts. ~jaco0646]
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions 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