Created
October 11, 2015 19:34
-
-
Save pl12133/b74c56f57998305db68c to your computer and use it in GitHub Desktop.
A simple timer written in AutoIt to make a noise after a countdown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Escape Key = {ESC} | |
; End Key = {END} | |
; Page Down = {PGDN} | |
; Page Up = {PGUP} | |
; For more: Google "Autoit Send" | |
[Hotkeys] | |
startKey={PGDN} | |
stopKey={PGUP} | |
[Duration] | |
countdown=29 | |
[Noise] | |
file=alert.mp3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;; | |
; simple_timer.au3 - Author Krirken | |
; A timer countdown, will count down from a value in the configuration file "config.ini" | |
; Use the configuration file to specify start/stop HotKeys for the timer | |
; A HotKeys normal function will be unavailable while the script is running (The key won't work like normal) | |
; You can also specify the timer duration and sound file to play at timer completion | |
; To exit the script, find it in the task bar and right+click and select 'Exit' | |
; FOR CHANGES IN THE CONFIG FILE TO TAKE EFFECT YOU MUST RESTART THE SCRIPT | |
;;;;; | |
Const $sCfgFilename = "config.ini" | |
Const $stopKey = IniRead($sCfgFilename, "Hotkeys", "stopKey", "{PGUP}") | |
Const $startKey = IniRead($sCfgFilename, "Hotkeys", "startKey", "{PGDN}") | |
Const $timerDuration = IniRead($sCfgFilename, "Duration", "countdown", "30") | |
Const $alertSoundFile = IniRead($sCfgFilename, "Noise", "file", "C:\Windows\media\notify.wav") | |
Local $time = 0 | |
; Setup Hotkeys to start and stop counting | |
HotKeySet($stopKey, StopCount) | |
HotKeySet($startKey, StartCount) | |
; StopCount is called when you press the stopKey from the configuration file | |
Func StopCount() | |
If ($time > 0) Then | |
;ConsoleWrite("Stopping Timer..." & @CRLF) | |
$time = -1 | |
EndIf | |
EndFunc | |
; StartCount is called when you press the startKey from the configuration file | |
Func StartCount() | |
;ConsoleWrite("Starting Timer..." & @CRLF) | |
if ($time <= 0) Then ; If the timer is not running (it is zero) | |
$time = $timerDuration ; Set the time to the timeDuration from the configuration file | |
Else | |
Return ; Do nothing if the timer is already running. | |
EndIf | |
While $time > 0 | |
Sleep(1000) | |
$time -= 1 | |
WEnd | |
; Play sound when finished | |
If ($time > -1) Then | |
SoundPlay($alertSoundFile) | |
;ConsoleWrite("Timer Finished..." & @CRLF) | |
EndIf | |
EndFunc | |
; Sleep forever because we are always listening for HotKeys | |
While True | |
Sleep(600000) | |
WEnd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment