AutoHotkey Community

It is currently May 26th, 2012, 4:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Simple Alert Reminder
PostPosted: March 29th, 2009, 3:50 pm 
Offline

Joined: March 10th, 2009, 12:59 pm
Posts: 14
Location: NC, USA
Thought I would give something back to the AutoHotkey community that has helped me out so much. I've only been using ahk for a short time and find it very powerful.

This probably already exists in some form somewhere in the forum, but thought I would post anyway. It was a good ahk learning experience for me.

Code:
/*

  A simple but useful routine to create single short-term reminders.  It uses the 1-9 keys,
  with two sets of modifiers for each key, creating 18 hotkeys.  The first modifier set is used
  to create one minute increment alerts, and the second for ten minute increment alerts.
 
  Demonstrates the use of the Hotkey command, to create hotkeys dynamically, the SetTimer
  command, and the A_ThisHotkey variable.  Because only one timer label is used for all
  hotkeys, if you set a new alert, while an existing alert is active, the existing one is
  replaced with the new.  Only one alert can ever be active at a time.
 
  Note: If you use a start sound that is longer than the timer period, the timer will be
  inaccurate.
 
*/

; 1 minute increment modifiers (used with the number keys 1-9
AlertMods1 := "^!"
; 10 minute increment modifiers (used with the number keys 1-9
AlertMods10 := "^!#"
; if you don't want an audible alert, set it's repeat to 0
; Change these sounds to whatever you want
AlertStartSound := A_WinDir . "\Media\ding.wav"
AlertStartSoundRepeat := 2
AlertFinishSound := A_WinDir . "\Media\Notify.wav"
AlertFinishSoundRepeat := 3

; create the hotkeys
Loop, 9
{
  Hotkey, %AlertMods1%%A_Index%, MyAlertHotkey
  Hotkey, %AlertMods10%%A_Index%, MyAlertHotkey
}
Return

MyAlertHotkey:
  StringTrimRight, mods, A_ThisHotkey, 1
  StringTrimLeft, key, A_ThisHotkey, StrLen(mods)
 
  ; is it a one minute increment or a ten minute increment?
  period := key * ((mods = AlertMods1) ? 60000 : 600000)
 
  SetTimer, MyAlertTimer, %period%
  Loop, %AlertStartSoundRepeat%
    SoundPlay, %AlertStartSound%, wait
Return

MyAlertTimer:
  SetTimer, MyAlertTimer, off
  StringTrimRight, mods, A_ThisHotkey, 1
  StringTrimLeft, key, A_ThisHotkey, StrLen(mods)

  numminutes := key * ((mods = AlertMods1) ? 1 : 10)

  ; adjust message to your preference
  SplashTextOn, 115, 0, %numminutes% MINUTE ALERT !!!
  Loop, %AlertFinishSoundRepeat%
    SoundPlay, %AlertFinishSound%, wait
  Sleep 1500
  SplashTextOff
Return

Please comment on both programming style and suggested functionality.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: maul.esel and 9 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