VascoNqs Posted August 17, 2013 Posted August 17, 2013 Hi everyone. First time autoit newbie (first post too). I need some help on my script because I can't code. I'm willing to give it a go though. What I want is an alarm clock that plays a sound and/or displays a message that the time is up. The user should input a time (in minutes) and click "start". When those minutes have passed, a sound is played and/or a message appears in the tray notification bar. This is what I learned after reading the documentation: How to set a variable: Dim $minutes How to ask for input: InputBox ( "Repeating Alarm", "How many minutes should pass between alarm repetitions?" , "30") How to play a sound: SoundPlay(@WindowsDir & "\media\notify.wav", 1) How to display a message box: MsgBox(0, "Repeating Alarm", "Time's up!") What I don't know: How to make the script count the minutes. How to tie this all together. I appreciate any help you can give me.
czardas Posted August 17, 2013 Posted August 17, 2013 (edited) There's still a lot of things you need to learn to put this stuff together. Firstly you should not use the Dim keyword because it has been depreciated. Use Local instead (or Global - always outside a function). I suggest you read about While loops, Timer functions, Sleep() and nested loops. Here's an example using some of these features. Try and understand the logic of the code. You could put this code inside another loop or inside a function. Try out some ideas you might have and see how you get on. ; Local $iSeconds = InputBox("Input", "Input Seconds") Local $iTimer = TimerInit() ; Start the timer While 1 ; This loop repeats until interrupted If TimerDiff($iTimer) >= $iSeconds * 1000 Then ; greater or equal to $iSeconds * 1000 miliseconds MsgBox(0, "Wake Up", "Time to get out of bed") ExitLoop ; Here we interrupt the loop EndIf Sleep(100) ; Sleep 100 miliseconds for the cpu to cool off WEnd ; The Sleep() is important if you wish to leave the script running a long time. You could also only use Sleep() and not bother with timers. Either way you need a way to interrupt the script. Perhaps a HotKey. Edited August 17, 2013 by czardas operator64 ArrayWorkshop
TheSeeker Posted August 17, 2013 Posted August 17, 2013 The easiest way I can think of is to put the process to sleep. Another way might be to get the current time and add the minutes to calculate the final time and then loop a conditional. Since this is your first time, I will suggest to learn a little bit about programming itself, then it will be easier. $minute = InputBox("Prompt" , "How many minutes?" , 30) ;get your time, store it in a variable while 1 ; Run a loop $time = $minute*60*1000 ;convert minute to miliseconds, because sleep works that way sleep($time) ;wait for th time ;play the music if you want, use shellexecute() MsgBox(0,0,"The time is up") WEnd This should work as you intend. "Let me win[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;], [/color]but if I cannot[color=rgb(68,68,68);font-family:arial, sans-serif;font-size:small;] win, let me be brave in the attempt"[/color]
VascoNqs Posted August 17, 2013 Author Posted August 17, 2013 Thanks czardas and TheSeeker. TheSeeker's example is perfect for me. It is simple enough so that I can run it as is and understand what's going on. I will take it and learn to adapt it to my needs.
VascoNqs Posted August 19, 2013 Author Posted August 19, 2013 (edited) Just in case someone wants a repeating alarm clock, here's what I did: $minute = InputBox("Repeating Alarm" , "How many minutes from now?" , 45) ;get your time, store it in a variable while 1 ; Run a loop $time = $minute*60*1000 ;convert minute to miliseconds, because sleep works that way sleep($time) ;wait for the time SoundPlay(@WindowsDir & "\media\notify.wav", 0) $minute = InputBox("Alarm" , "Hit OK and the alarm will reset." , $minute) WEnd Edited August 19, 2013 by VascoNqs
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now