AutoHotkey Community

It is currently May 25th, 2012, 12:05 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: July 22nd, 2007, 12:59 am 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
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 :P


Image

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 8)

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


Last edited by HuBa on December 10th, 2007, 10:13 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2007, 4:43 am 
Offline

Joined: March 9th, 2007, 2:47 am
Posts: 509
Location: Unknown
Cool i will probably use this


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2007, 6:05 am 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
Here is a cool countdown voice I found on the internet:
http://tinyurl.com/yotayp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2009, 4:45 pm 
Offline

Joined: September 6th, 2008, 3:11 pm
Posts: 84
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 ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 23rd, 2009, 9:31 pm 
Offline

Joined: February 24th, 2007, 6:02 pm
Posts: 175
Location: Budapest, Hungary
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2010, 4:55 pm 
Offline

Joined: December 2nd, 2009, 1:24 am
Posts: 2
Thx @HuBa for publishing this great little tool! :D

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

ps: I got my sound effect here: http://www.a1freesoundeffects.com/frees ... ockgun.wav

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

Greetings,
Manuel


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2010, 8:15 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
Sweeeeeet! Will be used for cooking. :) I'll try it eventually and get back with results.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2010, 1:59 pm 
Offline

Joined: December 2nd, 2009, 1:24 am
Posts: 2
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Ayuda, con el script
PostPosted: July 20th, 2010, 3:39 am 
Offline

Joined: July 19th, 2010, 12:39 pm
Posts: 2
Location: Acapulco
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]


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, JamixZol, kiropes and 40 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group