AutoHotkey Community

It is currently May 26th, 2012, 9:29 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: *nuked*
PostPosted: August 4th, 2009, 4:54 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:08 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 7:44 am 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
ThatGuySky: Fortunately, this sounds like a fun and relatively easy script. I'd be willing to give it a shot.

Edit: How about we make this a collaboration project where whatever you were going to pay the coder can be donated to AutoHotkey instead? I think that sounds like a great idea. You get better quality code, and we can all contribute to AHK and share the love. I'll get started and post some code when ready.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 4th, 2009, 10:03 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:09 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 11:19 am 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
ThatGuySky: Below is some crude code to get this project started. Some notes first.

I had to hard code things like the timers, labels and hotkeys because I am not sure how to make them dynamic. It would be very nice if someone could look through this and shed some light on what sections can be made more dynamic and how. I got to use some custom timer functions which I created a while ago which make it easy to get the elapsed time and the remaining time of a timer.

The script currently looks for some WAV files in a sub folder called Sounds. If you're on Windows XP it might already be able to play MP3 files, if not I'm certain there are many solutions readily available in the forums.

I also added a text control to display the remaining time of each alarm, which I think might be of interest to the user.

Code:
#Singleinstance force
SetWorkingDir %A_ScriptDir%

 Gosub, SetGlobals
 Gosub, CreateGui
 Gosub, ShowGui
 Gosub, StartUpdateGuiTimer
 Gosub, SaveSettings
return


SetGlobals:
 ProgramName    = FourTimer
 IniPath       = %A_Scriptdir%\FourTimer.ini
 SoundPath       = %A_Scriptdir%\Sounds
 PicturePath    = %A_Scriptdir%\Pictures
 TimerRestartThreshold := GetIni("General", "WarningSeconds")
return


CreateGui:
 Gui, Add, Text,    x231 y007 w290 h020 +Center, FourTimer
 Gui, Add, Picture, x046 y057 w120 h120 , %PicturePath%\Timer0.bmp
 Gui, Add, Picture, x196 y057 w120 h120 , %PicturePath%\Timer1.bmp
 Gui, Add, Picture, x336 y057 w150 h120 , %PicturePath%\Timer2.bmp
 Gui, Add, Picture, x496 y057 w170 h110 , %PicturePath%\Timer3.bmp
 
 Gui, Add, Text,    x006 y187 w050 h020 , Delay:
 Gui, Add, Text,    x006 y217 w050 h020 , Hotkey:
 Gui, Add, Text,    x006 y247 w050 h020 , Remaining:

 Gui, Add, Edit,    x066 y187 w090 h020 +Center vEditDelay0, 10
 Gui, Add, Edit,    x216 y187 w090 h020 +Center vEditDelay1, 15
 Gui, Add, Edit,    x356 y187 w100 h020 +Center vEditDelay2, 20
 Gui, Add, Edit,    x526 y187 w090 h020 +Center vEditDelay3, 25
 
 Gui, Add, Hotkey,  x066 y217 w090 h020 vHK0 Limit1, Numpad0
 Gui, Add, Hotkey,  x216 y217 w090 h020 vHK1 Limit1, Numpad1
 Gui, Add, Hotkey,  x356 y217 w100 h020 vHK2 Limit1, Numpad2
 Gui, Add, Hotkey,  x526 y217 w090 h020 vHK3 Limit1, Numpad3
 
 Gui, Add, Text,    x066 y247 w090 h020 +Center vRemaining0, 10
 Gui, Add, Text,    x216 y247 w090 h020 +Center vRemaining1, 15
 Gui, Add, Text,    x356 y247 w100 h020 +Center vRemaining2, 20
 Gui, Add, Text,    x526 y247 w090 h020 +Center vRemaining3, 25
 
 Gui, Add, Picture, x186 y277 w290 h050 , %windir%\Rhododendron.bmp
 Gui, Add, Button,    x046 y297 w100 h030 gSaveSettings, Save
 Gui, Add, Button,    x516 y297 w100 h030 gResetSettings, Default/Reset
Return


StartUpdateGuiTimer:
 SetMyTimer("UpdateGui", UpdateGui, 1000)
return


UpdateGui:
  Remaining0 := Round(GetMyTimer(Timer0) / 1000)
  Remaining1 := Round(GetMyTimer(Timer1) / 1000)
  Remaining2 := Round(GetMyTimer(Timer2) / 1000)
  Remaining3 := Round(GetMyTimer(Timer3) / 1000)
 
  if Remaining0 > -1
    GuiControl, , Remaining0, %Remaining0%
  if Remaining1 > -1   
   GuiControl, , Remaining1, %Remaining1%
  if Remaining2 > -1
   GuiControl, , Remaining2, %Remaining2%
  if Remaining3 > -1
   GuiControl, , Remaining3, %Remaining3%
return

HandleHotkey0:
 GuiControlGet, Delay, , EditDelay0
 ElapsedTime := GetMyTimer("Timer0", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("Timer0", Timer0, Delay * 1000) ;Start/Restart timer
  SetMyTimer("TimerWarning0", TimerWarning0, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer0", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey1:
 GuiControlGet, Delay, , EditDelay1
 ElapsedTime := GetMyTimer("Timer1", 2)
 if (ElapsedTime < TimerRestartThreshold * 1000)
 {
  SetMyTimer("Timer1", Timer1, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning1", TimerWarning1, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer1", "SoundStart")) ;Play sound when timer starts
 }
 else
 {
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 }
return


HandleHotkey2:
 GuiControlGet, Delay, , EditDelay2
 ElapsedTime := GetMyTimer("Timer2", 2)
 if (ElapsedTime < TimerRestartThreshold * 1000)
 {
  SetMyTimer("Timer2", Timer2, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning2", TimerWarning2, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer2", "SoundStart")) ;Play sound when timer starts
 }
 else
 {
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 }
return


HandleHotkey3:
 GuiControlGet, Delay, , EditDelay3
 ElapsedTime := GetMyTimer("Timer3", 2)
 if (ElapsedTime < TimerRestartThreshold * 1000)
 {
  SetMyTimer("Timer3", Timer3, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning3", TimerWarning3, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer3", "SoundStart")) ;Play sound when timer starts
 }
 else
 {
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 }
return


Timer0:
 SetTimer, Timer0, Off
 PlaySound(GetIni("Timer0", "SoundStop")) ;Play sound when timer stops
return


TimerWarning0:
 SetTimer, TimerWarning0, Off
 PlaySound(GetIni("Timer0", "SoundWarning")) ;Play warning sound 5 seconds before timer stops
return


Timer1:
 SetTimer, Timer1, Off
 PlaySound(GetIni("Timer1", "SoundStop")) ;Play sound when timer stops
return


TimerWarning1:
 SetTimer, TimerWarning1, Off
 PlaySound(GetIni("Timer1", "SoundWarning")) ;Play warning sound 5 seconds before timer stops
return


Timer2:
 SetTimer, Timer2, Off
 PlaySound(GetIni("Timer2", "SoundStop")) ;Play sound when timer stops
return


TimerWarning2:
 SetTimer, TimerWarning2, Off
 PlaySound(GetIni("Timer2", "SoundWarning")) ;Play warning sound 5 seconds before timer stops
return


Timer3:
 SetTimer, Timer3, Off
 PlaySound(GetIni("Timer3", "SoundStop")) ;Play sound when timer stops
return


TimerWarning3:
 SetTimer, TimerWarning3, Off
 PlaySound(GetIni("Timer3", "SoundWarning")) ;Play warning sound 5 seconds before timer stops
return


ShowGui:
 Gui, Show, h372 w697, %ProgramName%
return


SaveSettings:
 Gui +OwnDialogs
 gui, submit, nohide
 Hotkey, %HK0%, HandleHotkey0, On
 Hotkey, %HK1%, HandleHotkey1, On
 Hotkey, %HK2%, HandleHotkey2, On
 Hotkey, %HK3%, HandleHotkey3, On
return


ResetSettings:
 Gui +OwnDialogs
 msgbox, Reset GUI from ini
return


SetIni(Value, Section, Key)
{
 global IniPath
 IniWrite, %Value%, %IniPath%, %Section%, %Key%
}


GetIni(Section, Key)
{
 global IniPath
 IniRead, Value, %IniPath%, %Section%, %Key%
 return Value
}


SetMyTimer(label, byref TimerArray, Period = 250, Priority = 0)
{
 ;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
 ;msgbox, Label: %Label%`nTimerArray: %TimerArray%
 SetTimer, %Label%, %Period%, %Priority%
 TimerArray = %A_TickCount%|%Period%
}


GetMyTimer(TimerArray, Mode = 3)
{
;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
;Modes: 1 = Return total time, 2 = Return elapsed time, 3 = Return remaining time
 StringSplit, TimerArray, TimerArray, |
 ElapsedTime := A_TickCount - TimerArray1
 RemainingTime := TimerArray2 - ElapsedTime
 StringLower, mode, mode
 if mode = 1
    return TimerArray2
 else if mode = 2
  return ElapsedTime
 else if mode = 3
  return RemainingTime
 else
  return 1 ;Error. Unexpected value for mode
}

PlaySound(FileName)
{
 global SoundPath
 SoundPlay, %SoundPath%\%Filename%
}


GuiClose:
ExitApp


Ini file:
Quote:
[General]
WarningSeconds=5

[Timer0]
Hotkey=
SoundStart=Timer0Start.wav
SoundStop=Timer0Stop.wav
SoundWarning=Timer0Warning.wav
Picture=

[Timer1]
Hotkey=
SoundStart=Timer1Start.wav
SoundStop=Timer1Stop.wav
SoundWarning=Timer1Warning.wav
Picture=

[Timer2]
Hotkey=
SoundStart=Timer2Start.wav
SoundStop=Timer2Stop.wav
SoundWarning=Timer2Warning.wav
Picture=

[Timer3]
Hotkey=
SoundStart=Timer3Start.wav
SoundStop=Timer3Stop.wav
SoundWarning=Timer3Warning.wav
Picture=


Is anyone else willing to contribute to this?


Last edited by Murp|e on August 4th, 2009, 1:09 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 4th, 2009, 11:46 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:09 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 4th, 2009, 12:22 pm 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:10 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 12:47 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
ThatGuySky wrote:
1) Is there anyway to have the timer start instantly when the button is pressed?

The timers actually start instantly, but the GUI/interface is currently set to update every second, which is why it looks like there is a delay. This should probably be addressed though.


ThatGuySky wrote:
I've noticed through testing that it waits until the .wav file is finished playing before it will start the actual countdown causing a bit of latency.

You're right. I modified the code so that it no longer waits until the file is finished playing. I also rearranged it slightly so that it starts the timers first, then plays the sound. To quote the help file: "If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play."


ThatGuySky wrote:
2) Also, I can't for the life of me figure out how to change the pictures to something in a Pictures directory inside the main directory. It looks like they are currently set to windir and when I try to modify this in SmartGUI it loses the code.

Although you can probably use SmartGUI to modify this GUI, I find it is better to modify existing GUIs directly in the code. I have changed the code to point to the Pictures folder instead of the Windows folder. Try it again, it should now work as expected. (It expects to find four images in the Pictures folder named Timer0.bmp - Timer3.bmp)

ThatGuySky wrote:
3) Just for testing purposes I was trying to convert it to a .exe and it doesn't recognize the gSave or gReset commands issued in the script.

I'm not entirely sure what you mean, but the Save and Rest buttons are not really implemented yet.

In general the script is rather unfinished and unpolished. Perhaps you can use SmartGUI to finalize the GUI and I can integrate it with the code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 4th, 2009, 12:58 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
There is no Donate button (Of course I already knew that!!), but the site owner Chris has provided an automatic PayPal link here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 5th, 2009, 7:27 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:11 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 5th, 2009, 7:46 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:12 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 7:54 am 
Offline

Joined: June 12th, 2009, 11:36 pm
Posts: 1173
Location: Indianapolis IN, USA
I was curious why you needed this script? Is it for some kind of game?

_________________
www.AutoHotkey.net/~Eedis
I love my wife and daughter so much.
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 5th, 2009, 9:09 am 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:12 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 5th, 2009, 3:35 pm 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
ThatGuySky wrote:
...is it possible to have the sounds overlap each other in the chance that the timers are roughly the same?

Yes, I've modified the script to use a workaround provided in this post.

ThatGuySky wrote:
I have everything just the way I want it.. however when I go to compile the script to a .exe it fails. It gives me a partial .exe about 410kb and when I run it, i says ".EXE Corrupt"

I have no idea why it fails to compile on your machine. I will email you the whole project, if you still want to compile from source, I suggest you download and install AutoHotkey and try again. Good luck with your tournaments and I really hope you donate something considering I put it many hours on this.

ThatGuySky wrote:
I have removed the Save/Reset functions as those are not yet implemented

I've now implemented the Save/Reset buttons. Clicking on save will save the timer and hotkey to the ini file. Reset will read the settings from the ini file and set the GUI controls and stop any active timers.

The script now minimizes to the system tray instead of showing up in the taskbar. Hovering over the tray icon will display any currently active timers and clicking on the tray will display the interface. All the media (Pictures, sounds, icon) can be configured from the ini file or by replacing the existing media files, but keeping the same file names. I added a setting in the ini called HotkeysAreGlobal which is set to 1 by default. I you set it to 0, the hotkeys will only work when the GUI is the active window.

I'll admit I thought -for no reason at all- that this was going to be used for something a little more serious than a game trainer, but I've learned a few things while working on this and although the final code is about four times as big as it should be (Most of the code is 4x because of the 4 timers) I'm rather pleased with the final result and I hope you are too.

You have the entire source so you can modify it as you see fit. If you want to use SmartGUI to modify the GUI I suggest you not use it directly on the script, but rather examine the resulting code from SmartGUI and manually make the adjustments.

TimeTrainer.ahk
Code:
#Singleinstance force
SetWorkingDir %A_ScriptDir%

 Gosub, SetGlobals
 Gosub, CreateTrayMenu
 Gosub, CreateGui
 Gosub, SetGuiDefaults
 Gosub, ShowGui
 Gosub, StartUpdateGuiTimer
 Gosub, ActivateHotkeys
return


SetGlobals:
 IniPath             = %A_Scriptdir%\Settings.ini
 SoundPath             = %A_Scriptdir%\Sounds
 PicturePath          = %A_Scriptdir%\Pictures
 ProgramName          := GetIni("General", "ProgramName")
 TimerRestartThreshold := GetIni("General", "WarningSeconds")
return


CreateTrayMenu:
 ProgramIconPath := PicturePath . "" . GetIni("General", "ProgramIcon")
 menu, tray, tip, %ProgramName%
 menu, tray, icon, %ProgramIconPath%
 Menu, Tray, Click, 1
 menu, tray, NoStandard
 menu, tray, add, &Configure, Configure
 menu, tray, add, &Exit, Exit
 menu, tray, default, &Configure
return


Configure:
 gui, show
return


CreateGui:
 gui, +owner
 gui, font, s20 cNavy, Verdana 
 Gui, Add, Text,    x200 y05 w300 h040 +Center, %ProgramName%
 gui, font
 
 Gui, Add, Picture, x075 y050 w100 h100 Border vPicture0, %Picture0Path%
 Gui, Add, Picture, x225 y050 w100 h100 Border vPicture1,  %Picture1Path%
 Gui, Add, Picture, x375 y050 w100 h100 Border vPicture2, %Picture2Path%
 Gui, Add, Picture, x525 y050 w100 h100 Border vPicture3, %Picture3Path%
 
 Gui, Add, Text,    x005 y170 w055 h020 , Alarm:
 Gui, Add, Text,    x005 y190 w055 h020 , Hotkey:
 Gui, Add, Text,    x005 y210 w055 h020 , Remaining:

 Gui, Add, Edit,    x075 y170 w100 h020 limit number +Center vEditDelay0,
 Gui, Add, Edit,    x225 y170 w100 h020 limit number +Center vEditDelay1,
 Gui, Add, Edit,    x375 y170 w100 h020 limit number +Center vEditDelay2,
 Gui, Add, Edit,    x525 y170 w100 h020 limit number +Center vEditDelay3,
 
 Gui, Add, Hotkey,  x075 y190 w100 h020 vHK0 +Center,
 Gui, Add, Hotkey,  x225 y190 w100 h020 vHK1 +Center,
 Gui, Add, Hotkey,  x375 y190 w100 h020 vHK2 +Center,
 Gui, Add, Hotkey,  x525 y190 w100 h020 vHK3 +Center,
 
 Gui, Add, Text,    x075 y210 w100 h020 +Center vRemaining0
 Gui, Add, Text,    x225 y210 w100 h020 +Center vRemaining1
 Gui, Add, Text,    x375 y210 w100 h020 +Center vRemaining2
 Gui, Add, Text,    x525 y210 w100 h020 +Center vRemaining3
 
 Gui, Add, Picture, x400 y250 w300 h050 Border vProgramLogo

 Gui, Add, Button,    x050 y250 w100 h030 gSaveSettings, Save
 Gui, Add, Button,    x200 y250 w100 h030 gSetGuiDefaults, Reset
Return


SetGuiDefaults:
 Picture0Path := PicturePath . "" . GetIni("Timer0", "Picture")
 Picture1Path := PicturePath . "" . GetIni("Timer1", "Picture")
 Picture2Path := PicturePath . "" . GetIni("Timer2", "Picture")
 Picture3Path := PicturePath . "" . GetIni("Timer3", "Picture")
 ProgramLogoPath := PicturePath . "" . GetIni("General", "ProgramLogo")
 GuiControl, , Picture0, %Picture0Path%
 GuiControl, , Picture1, %Picture1Path%
 GuiControl, , Picture2, %Picture2Path%
 GuiControl, , Picture3, %Picture3Path%
 GuiControl, , ProgramLogo, %ProgramLogoPath%
 
 Timer0DefaultDelay := GetIni("Timer0", "TimerSeconds")
 Timer1DefaultDelay := GetIni("Timer1", "TimerSeconds")
 Timer2DefaultDelay := GetIni("Timer2", "TimerSeconds")
 Timer3DefaultDelay := GetIni("Timer3", "TimerSeconds")
 GuiControl, , EditDelay0, %Timer0DefaultDelay%
 GuiControl, , EditDelay1, %Timer1DefaultDelay%
 GuiControl, , EditDelay2, %Timer2DefaultDelay%
 GuiControl, , EditDelay3, %Timer3DefaultDelay%
 
 GuiControl, , Remaining0
 GuiControl, , Remaining1
 GuiControl, , Remaining2
 GuiControl, , Remaining3

 Timer0DefaultHotkey := GetIni("Timer0", "Hotkey")
 Timer1DefaultHotkey := GetIni("Timer1", "Hotkey")
 Timer2DefaultHotkey := GetIni("Timer2", "Hotkey")
 Timer3DefaultHotkey := GetIni("Timer3", "Hotkey")
 GuiControl, , HK0, %Timer0DefaultHotkey%
 GuiControl, , HK1, %Timer1DefaultHotkey%
 GuiControl, , HK2, %Timer2DefaultHotkey%
 GuiControl, , HK3, %Timer3DefaultHotkey%
 
 ;Kill all timers
 SetMyTimer("Timer0", Timer0, "Off")
 SetMyTimer("TimerWarning0", TimerWarning0, "Off")
 SetMyTimer("Timer1", Timer1, "Off")
 SetMyTimer("TimerWarning1", TimerWarning1, "Off")
 SetMyTimer("Timer2", Timer2, "Off")
 SetMyTimer("TimerWarning2", TimerWarning2, "Off")
 SetMyTimer("Timer3", Timer3, "Off")
 SetMyTimer("TimerWarning3", TimerWarning3, "Off")
 
 
 SetTimer, TimerWarning0, Off
 SetTimer, Timer1, Off
 SetTimer, TimerWarning1, Off
 SetTimer, Timer2, Off
 SetTimer, TimerWarning2, Off
 SetTimer, Timer3, Off
 SetTimer, TimerWarning3, Off
return


SaveSettings:
 gui, +owndialogs
 gosub, ActivateHotkeys
 gui, submit, nohide
 SetIni("Timer0", "TimerSeconds", GetControl("EditDelay0"))
 SetIni("Timer1", "TimerSeconds", GetControl("EditDelay1"))
 SetIni("Timer2", "TimerSeconds", GetControl("EditDelay2"))
 SetIni("Timer3", "TimerSeconds", GetControl("EditDelay3"))
 
 SetIni("Timer0", "Hotkey", GetControl("HK0"))
 SetIni("Timer1", "Hotkey", GetControl("HK1"))
 SetIni("Timer2", "Hotkey", GetControl("HK2"))
 SetIni("Timer3", "Hotkey", GetControl("HK3"))
 MsgBox,, %ProgramName%, Settings saved.
return


StartUpdateGuiTimer:
 gosub, UpdateGui
 SetMyTimer("UpdateGui", UpdateGui, 500)
return


UpdateGui:
 if Round(GetMyTimer(Timer0) / 1000) > 0
  Remaining0 := Round(GetMyTimer(Timer0) / 1000)
 else
  Remaining0 := ""
   
 if Round(GetMyTimer(Timer1) / 1000) > 0
  Remaining1 := Round(GetMyTimer(Timer1) / 1000)
 else
  Remaining1 := ""
 
 if Round(GetMyTimer(Timer2) / 1000) > 0
  Remaining2 := Round(GetMyTimer(Timer2) / 1000)
 else
  Remaining2 := ""
   
 if Round(GetMyTimer(Timer3) / 1000) > 0
  Remaining3 := Round(GetMyTimer(Timer3) / 1000)
 else
  Remaining3 := ""
 
 GuiControl, , Remaining0, %Remaining0%
 GuiControl, , Remaining1, %Remaining1%
 GuiControl, , Remaining2, %Remaining2%
 GuiControl, , Remaining3, %Remaining3%
 
 if Remaining0 > 0
  Timer0Title := "`n" . GetIni("Timer0", "Title") . ": "
 else
  Timer0Title := ""
 
  if Remaining1 > 0
  Timer1Title := "`n" . GetIni("Timer1", "Title") . ": "
 else
  Timer1Title := ""
 
  if Remaining2 > 0
  Timer2Title := "`n" . GetIni("Timer2", "Title") . ": "
 else
  Timer2Title := ""
 
  if Remaining3 > 0
  Timer3Title := "`n" . GetIni("Timer3", "Title") . ": "
 else
  Timer3Title := ""

 menu, tray, tip, %ProgramName%%Timer0Title%%Remaining0%%Timer1Title%%Remaining1%%Timer2Title%%Remaining2%%Timer3Title%%Remaining3%
return


HandleHotkey0:
 GuiControlGet, Delay, , EditDelay0
 ElapsedTime := GetMyTimer("Timer0", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("Timer0", Timer0, Delay * 1000) ;Start/Restart timer
  SetMyTimer("TimerWarning0", TimerWarning0, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer0", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey1:
 GuiControlGet, Delay, , EditDelay1
 ElapsedTime := GetMyTimer("Timer1", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer1", Timer1, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning1", TimerWarning1, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer1", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey2:
 GuiControlGet, Delay, , EditDelay2
 ElapsedTime := GetMyTimer("Timer2", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer2", Timer2, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning2", TimerWarning2, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer2", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey3:
 GuiControlGet, Delay, , EditDelay3
 ElapsedTime := GetMyTimer("Timer3", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer3", Timer3, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning3", TimerWarning3, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer3", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


Timer0:
 SetTimer, Timer0, Off
 PlaySound(GetIni("Timer0", "SoundStop"))
return


TimerWarning0:
 SetTimer, TimerWarning0, Off
 PlaySound(GetIni("Timer0", "SoundWarning"))
return


Timer1:
 SetTimer, Timer1, Off
 PlaySound(GetIni("Timer1", "SoundStop"))
return


TimerWarning1:
 SetTimer, TimerWarning1, Off
 PlaySound(GetIni("Timer1", "SoundWarning"))
return


Timer2:
 SetTimer, Timer2, Off
 PlaySound(GetIni("Timer2", "SoundStop"))
return


TimerWarning2:
 SetTimer, TimerWarning2, Off
 PlaySound(GetIni("Timer2", "SoundWarning"))
return


Timer3:
 SetTimer, Timer3, Off
 PlaySound(GetIni("Timer3", "SoundStop"))
return


TimerWarning3:
 SetTimer, TimerWarning3, Off
 PlaySound(GetIni("Timer3", "SoundWarning"))
return


ShowGui:
 Gui, Show, w700 h300, %ProgramName%
return


ActivateHotkeys:
 If HK0
  Hotkey, %HK0%, Off
 If HK1
  Hotkey, %HK1%, Off
 If HK2
  Hotkey, %HK2%, Off
 If HK3
  Hotkey, %HK3%, Off
 
 gui, submit, nohide
 if GetIni("General", "HotkeysAreGlobal")
 {
  Hotkey, IfWinActive
  Hotkey, %HK0%, HandleHotkey0, On
  Hotkey, %HK1%, HandleHotkey1, On
  Hotkey, %HK2%, HandleHotkey2, On
  Hotkey, %HK3%, HandleHotkey3, On
 }
 else
 {
  gui, +LastFoundExist
  GuiId := WinExist()
  Hotkey, IfWinActive, ahk_id %GuiId%
  Hotkey, %HK0%, HandleHotkey0, On
  Hotkey, %HK1%, HandleHotkey1, On
  Hotkey, %HK2%, HandleHotkey2, On
  Hotkey, %HK3%, HandleHotkey3, On
 }
return


Exit:
GuiClose:
 exitapp
return


GuiSize:
 if A_EventInfo = 1
 {
  gui, show, hide
 }
return


SetIni(Section, Key, Value)
{
 global IniPath
 IniWrite, %Value%, %IniPath%, %Section%, %Key%
 return %errorlevel%
}


GetControl(ControlID)
{
 GuiControlGet, Value, , %ControlID%
 return %Value%
}


GetIni(Section, Key)
{
 global IniPath
 IniRead, Value, %IniPath%, %Section%, %Key%
 return Value
}


SetMyTimer(label, byref TimerArray, Period = 250, Priority = 0)
{
 ;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
 ;msgbox, Label: %Label%`nTimerArray: %TimerArray%
 SetTimer, %Label%, %Period%, %Priority%
 TimerArray = %A_TickCount%|%Period%
}


GetMyTimer(TimerArray, Mode = 3)
{
;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
;Modes: 1 = Return total time, 2 = Return elapsed time, 3 = Return remaining time
 StringSplit, TimerArray, TimerArray, |
 if (TimerArray1  = "Off")
 {
  TimerArray2 := ""
  ElapsedTime := ""
  RemainingTime := ""
 }
 else
 {
  ElapsedTime := A_TickCount - TimerArray1
  RemainingTime := TimerArray2 - ElapsedTime
 }
 StringLower, mode, mode
 if mode = 1
    return TimerArray2
 else if mode = 2
  return ElapsedTime
 else if mode = 3
  return RemainingTime
 else
  return 1 ;Error. Unexpected value for mode
}


PlaySound(FileName)
{
;Trubbleguy http://www.autohotkey.com/forum/viewtopic.php?p=231332#231332
 global SoundPath
 run, %A_ScriptDir%\PlaySound.exe "%SoundPath%\%Filename%"
}


PlaySound.ahk
Code:
#NoTrayIcon
SoundPlay,%1%,wait
exitapp


Settings.ini
Code:
[General]
ProgramName=TimeTrainer
ProgramIcon=trayicon.ico
ProgramLogo=Logo.bmp
Version=1.0
WarningSeconds=5
HotkeysAreGlobal=1


[Timer0]
Title=Timer1
Hotkey=^D
TimerSeconds=10
SoundStart=Timer0Start.wav
SoundStop=Timer0Stop.wav
SoundWarning=Timer0Warning.wav
Picture=Timer0.bmp


[Timer1]
Title=Timer2
Hotkey=^F
TimerSeconds=20
SoundStart=Timer1Start.wav
SoundStop=Timer1Stop.wav
SoundWarning=Timer1Warning.wav
Picture=Timer1.bmp


[Timer2]
Title=Timer3
Hotkey=^G
TimerSeconds=30
SoundStart=Timer2Start.wav
SoundStop=Timer2Stop.wav
SoundWarning=Timer2Warning.wav
Picture=Timer2.bmp


[Timer3]
Title=Timer4
Hotkey=^H
TimerSeconds=40
SoundStart=Timer3Start.wav
SoundStop=Timer3Stop.wav
SoundWarning=Timer3Warning.wav
Picture=Timer3.bmp


Report this post
Top
 Profile  
Reply with quote  
 Post subject: *nuked*
PostPosted: August 5th, 2009, 8:36 pm 
Offline

Joined: August 4th, 2009, 2:51 am
Posts: 20
Redacted.


Last edited by ThatGuySky on January 5th, 2012, 8:12 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 6th, 2009, 9:03 am 
Offline

Joined: January 12th, 2007, 4:30 am
Posts: 531
Location: Norway
ThatGuySky wrote:
I have the PayPal information and am planning to make a generous donation this Friday. May I have your PayPal information as well?

I'm not sure I even have a PayPal account, just donate to AHK/Chris and it's all good.

ThatGuySky wrote:
I'd like to learn AutoHotKey eventually... ...However I haven't been able to find any decent tutorial :/

Check the front page of www.autohotkey.com?

ThatGuySky wrote:
Can you create a seperate identical script for the timer removing the ability to change the delay and pictures?

Yes. I disabled the edit fields for the timer delay, but since I don't know what delay you want you need to edit the source yourself, see lines 20-24.

For the pictures to be static, the simplest solution was to include the pictures in the compiled version of the script. This means that all the picture files will be packed in the exe when compiled and unpacked from the exe each time the program is run (Similar to zip/unzip). For this to work, you need to place all the picture files in the same folder as the source before you compile it, see lines 31-36 for the file names it expects.

I've made minor modifications elsewhere in the script so that it disregards the ini file with regards to the above mentioned delays and picture files. When using this version of the script you can delete the lines in the ini file that deal with the pictures and the delays.

Here is the new "locked up" version:
Code:
#Singleinstance force
SetWorkingDir %A_ScriptDir%

 Gosub, SetGlobals
 Gosub, UnpackPictures
 Gosub, CreateTrayMenu
 Gosub, CreateGui
 Gosub, SetGuiDefaults
 Gosub, ShowGui
 Gosub, StartUpdateGuiTimer
 Gosub, ActivateHotkeys
return


SetGlobals:
 IniPath             = %A_Scriptdir%\Settings.ini
 SoundPath             = %A_Scriptdir%\Sounds
 PicturePath          = %A_Scriptdir%\Pictures
 ProgramName          := GetIni("General", "ProgramName")
 TimerRestartThreshold  := 1  ;Edit this line
 DefaultDelay0          := 2  ;Edit this line
 DefaultDelay1          := 3  ;Edit this line
 DefaultDelay2          := 4  ;Edit this line
 DefaultDelay3          := 5  ;Edit this line
return


UnpackPictures:
 IfNotExist, %picturepath%
  filecreatedir, %picturepath%
 fileinstall, Logo.bmp,          %PicturePath%\Logo.bmp,       1 ;Before compiling, this file must be in the same folder as this script
 fileinstall, Timer0.bmp,          %PicturePath%\Timer0.bmp,       1 ;Before compiling, this file must be in the same folder as this script
 fileinstall, Timer1.bmp,          %PicturePath%\Timer1.bmp,       1 ;Before compiling, this file must be in the same folder as this script
 fileinstall, Timer2.bmp,          %PicturePath%\Timer2.bmp,       1 ;Before compiling, this file must be in the same folder as this script
 fileinstall, Timer3.bmp,          %PicturePath%\Timer3.bmp,       1 ;Before compiling, this file must be in the same folder as this script
 fileinstall, trayicon.ico,       %PicturePath%\trayicon.ico,    1 ;Before compiling, this file must be in the same folder as this script
return


CreateTrayMenu:
 ProgramIconPath := PicturePath . "\trayicon.ico"
 menu, tray, tip, %ProgramName%
 menu, tray, icon, %ProgramIconPath%
 Menu, Tray, Click, 1
 menu, tray, NoStandard
 menu, tray, add, &Configure, Configure
 menu, tray, add, &Exit, Exit
 menu, tray, default, &Configure
return


Configure:
 gui, show
return


CreateGui:
 gui, +owner
 gui, font, s20 cNavy, Verdana 
 Gui, Add, Text,    x200 y05 w300 h040 +Center, %ProgramName%
 gui, font
 
 Gui, Add, Picture, x075 y050 w100 h100 Border vPicture0
 Gui, Add, Picture, x225 y050 w100 h100 Border vPicture1
 Gui, Add, Picture, x375 y050 w100 h100 Border vPicture2
 Gui, Add, Picture, x525 y050 w100 h100 Border vPicture3
 
 Gui, Add, Text,    x005 y170 w055 h020 , Alarm:
 Gui, Add, Text,    x005 y190 w055 h020 , Hotkey:
 Gui, Add, Text,    x005 y210 w055 h020 , Remaining:

 Gui, Add, Edit,    x075 y170 w100 h020 limit number +Center +ReadOnly vEditDelay0,
 Gui, Add, Edit,    x225 y170 w100 h020 limit number +Center +ReadOnly vEditDelay1,
 Gui, Add, Edit,    x375 y170 w100 h020 limit number +Center +ReadOnly vEditDelay2,
 Gui, Add, Edit,    x525 y170 w100 h020 limit number +Center +ReadOnly vEditDelay3,
 
 Gui, Add, Hotkey,  x075 y190 w100 h020 vHK0 +Center,
 Gui, Add, Hotkey,  x225 y190 w100 h020 vHK1 +Center,
 Gui, Add, Hotkey,  x375 y190 w100 h020 vHK2 +Center,
 Gui, Add, Hotkey,  x525 y190 w100 h020 vHK3 +Center,
 
 Gui, Add, Text,    x075 y210 w100 h020 +Center vRemaining0
 Gui, Add, Text,    x225 y210 w100 h020 +Center vRemaining1
 Gui, Add, Text,    x375 y210 w100 h020 +Center vRemaining2
 Gui, Add, Text,    x525 y210 w100 h020 +Center vRemaining3
 
 Gui, Add, Picture, x400 y250 w300 h050 Border vProgramLogo

 Gui, Add, Button,    x050 y250 w100 h030 gSaveSettings, Save
 Gui, Add, Button,    x200 y250 w100 h030 gSetGuiDefaults, Reset
Return


SetGuiDefaults:
 Picture0Path := PicturePath . "\timer0.bmp"
 Picture1Path := PicturePath . "\timer1.bmp"
 Picture2Path := PicturePath . "\timer2.bmp"
 Picture3Path := PicturePath . "\timer3.bmp"
 ProgramLogoPath := PicturePath . "\Logo.bmp"
 GuiControl, , Picture0,    %Picture0Path%
 GuiControl, , Picture1,    %Picture1Path%
 GuiControl, , Picture2,    %Picture2Path%
 GuiControl, , Picture3,    %Picture3Path%
 GuiControl, , ProgramLogo, %ProgramLogoPath%
 
 Timer0DefaultDelay := GetIni("Timer0", "TimerSeconds")
 Timer1DefaultDelay := GetIni("Timer1", "TimerSeconds")
 Timer2DefaultDelay := GetIni("Timer2", "TimerSeconds")
 Timer3DefaultDelay := GetIni("Timer3", "TimerSeconds")
 GuiControl, , EditDelay0, %DefaultDelay0%
 GuiControl, , EditDelay1, %DefaultDelay1%
 GuiControl, , EditDelay2, %DefaultDelay2%
 GuiControl, , EditDelay3, %DefaultDelay3%
 
 GuiControl, , Remaining0
 GuiControl, , Remaining1
 GuiControl, , Remaining2
 GuiControl, , Remaining3

 Timer0DefaultHotkey := GetIni("Timer0", "Hotkey")
 Timer1DefaultHotkey := GetIni("Timer1", "Hotkey")
 Timer2DefaultHotkey := GetIni("Timer2", "Hotkey")
 Timer3DefaultHotkey := GetIni("Timer3", "Hotkey")
 GuiControl, , HK0, %Timer0DefaultHotkey%
 GuiControl, , HK1, %Timer1DefaultHotkey%
 GuiControl, , HK2, %Timer2DefaultHotkey%
 GuiControl, , HK3, %Timer3DefaultHotkey%
 
 ;Kill all timers
 SetMyTimer("Timer0", Timer0, "Off")
 SetMyTimer("TimerWarning0", TimerWarning0, "Off")
 SetMyTimer("Timer1", Timer1, "Off")
 SetMyTimer("TimerWarning1", TimerWarning1, "Off")
 SetMyTimer("Timer2", Timer2, "Off")
 SetMyTimer("TimerWarning2", TimerWarning2, "Off")
 SetMyTimer("Timer3", Timer3, "Off")
 SetMyTimer("TimerWarning3", TimerWarning3, "Off")
 
 
 SetTimer, TimerWarning0, Off
 SetTimer, Timer1, Off
 SetTimer, TimerWarning1, Off
 SetTimer, Timer2, Off
 SetTimer, TimerWarning2, Off
 SetTimer, Timer3, Off
 SetTimer, TimerWarning3, Off
return


SaveSettings:
 gui, +owndialogs
 gosub, ActivateHotkeys
 gui, submit, nohide
 SetIni("Timer0", "TimerSeconds", GetControl("EditDelay0"))
 SetIni("Timer1", "TimerSeconds", GetControl("EditDelay1"))
 SetIni("Timer2", "TimerSeconds", GetControl("EditDelay2"))
 SetIni("Timer3", "TimerSeconds", GetControl("EditDelay3"))
 
 SetIni("Timer0", "Hotkey", GetControl("HK0"))
 SetIni("Timer1", "Hotkey", GetControl("HK1"))
 SetIni("Timer2", "Hotkey", GetControl("HK2"))
 SetIni("Timer3", "Hotkey", GetControl("HK3"))
 MsgBox,, %ProgramName%, Settings saved.
return


StartUpdateGuiTimer:
 gosub, UpdateGui
 SetMyTimer("UpdateGui", UpdateGui, 500)
return


UpdateGui:
 if Round(GetMyTimer(Timer0) / 1000) > 0
  Remaining0 := Round(GetMyTimer(Timer0) / 1000)
 else
  Remaining0 := ""
   
 if Round(GetMyTimer(Timer1) / 1000) > 0
  Remaining1 := Round(GetMyTimer(Timer1) / 1000)
 else
  Remaining1 := ""
 
 if Round(GetMyTimer(Timer2) / 1000) > 0
  Remaining2 := Round(GetMyTimer(Timer2) / 1000)
 else
  Remaining2 := ""
   
 if Round(GetMyTimer(Timer3) / 1000) > 0
  Remaining3 := Round(GetMyTimer(Timer3) / 1000)
 else
  Remaining3 := ""
 
 GuiControl, , Remaining0, %Remaining0%
 GuiControl, , Remaining1, %Remaining1%
 GuiControl, , Remaining2, %Remaining2%
 GuiControl, , Remaining3, %Remaining3%
 
 if Remaining0 > 0
  Timer0Title := "`n" . GetIni("Timer0", "Title") . ": "
 else
  Timer0Title := ""
 
  if Remaining1 > 0
  Timer1Title := "`n" . GetIni("Timer1", "Title") . ": "
 else
  Timer1Title := ""
 
  if Remaining2 > 0
  Timer2Title := "`n" . GetIni("Timer2", "Title") . ": "
 else
  Timer2Title := ""
 
  if Remaining3 > 0
  Timer3Title := "`n" . GetIni("Timer3", "Title") . ": "
 else
  Timer3Title := ""

 menu, tray, tip, %ProgramName%%Timer0Title%%Remaining0%%Timer1Title%%Remaining1%%Timer2Title%%Remaining2%%Timer3Title%%Remaining3%
return


HandleHotkey0:
 GuiControlGet, Delay, , EditDelay0
 ElapsedTime := GetMyTimer("Timer0", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("Timer0", Timer0, Delay * 1000) ;Start/Restart timer
  SetMyTimer("TimerWarning0", TimerWarning0, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer0", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey1:
 GuiControlGet, Delay, , EditDelay1
 ElapsedTime := GetMyTimer("Timer1", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer1", Timer1, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning1", TimerWarning1, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer1", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey2:
 GuiControlGet, Delay, , EditDelay2
 ElapsedTime := GetMyTimer("Timer2", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer2", Timer2, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning2", TimerWarning2, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer2", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


HandleHotkey3:
 GuiControlGet, Delay, , EditDelay3
 ElapsedTime := GetMyTimer("Timer3", 2)
 ;if (ElapsedTime < TimerRestartThreshold * 1000)
 ;{
  SetMyTimer("Timer3", Timer3, Delay * 1000) ;Start/Restart timer
  WarningTime := (Delay - TimerRestartThreshold) * 1000
  SetMyTimer("TimerWarning3", TimerWarning3, WarningTime) ;Start/Restart timer to sound warning alarm 5 seconds before above timer
  PlaySound(GetIni("Timer3", "SoundStart")) ;Play sound when timer starts
 ;}
 ;else
 ;{
  ;What to do if hotkey is pressed but more than 5 seconds have passed?
 ;}
return


Timer0:
 SetTimer, Timer0, Off
 PlaySound(GetIni("Timer0", "SoundStop"))
return


TimerWarning0:
 SetTimer, TimerWarning0, Off
 PlaySound(GetIni("Timer0", "SoundWarning"))
return


Timer1:
 SetTimer, Timer1, Off
 PlaySound(GetIni("Timer1", "SoundStop"))
return


TimerWarning1:
 SetTimer, TimerWarning1, Off
 PlaySound(GetIni("Timer1", "SoundWarning"))
return


Timer2:
 SetTimer, Timer2, Off
 PlaySound(GetIni("Timer2", "SoundStop"))
return


TimerWarning2:
 SetTimer, TimerWarning2, Off
 PlaySound(GetIni("Timer2", "SoundWarning"))
return


Timer3:
 SetTimer, Timer3, Off
 PlaySound(GetIni("Timer3", "SoundStop"))
return


TimerWarning3:
 SetTimer, TimerWarning3, Off
 PlaySound(GetIni("Timer3", "SoundWarning"))
return


ShowGui:
 Gui, Show, w700 h300, %ProgramName%
return


ActivateHotkeys:
 If HK0
  Hotkey, %HK0%, Off
 If HK1
  Hotkey, %HK1%, Off
 If HK2
  Hotkey, %HK2%, Off
 If HK3
  Hotkey, %HK3%, Off
 
 gui, submit, nohide
 if GetIni("General", "HotkeysAreGlobal")
 {
  Hotkey, IfWinActive
  Hotkey, %HK0%, HandleHotkey0, On
  Hotkey, %HK1%, HandleHotkey1, On
  Hotkey, %HK2%, HandleHotkey2, On
  Hotkey, %HK3%, HandleHotkey3, On
 }
 else
 {
  gui, +LastFoundExist
  GuiId := WinExist()
  Hotkey, IfWinActive, ahk_id %GuiId%
  Hotkey, %HK0%, HandleHotkey0, On
  Hotkey, %HK1%, HandleHotkey1, On
  Hotkey, %HK2%, HandleHotkey2, On
  Hotkey, %HK3%, HandleHotkey3, On
 }
return


Exit:
GuiClose:
 exitapp
return


GuiSize:
 if A_EventInfo = 1
 {
  gui, show, hide
 }
return


SetIni(Section, Key, Value)
{
 global IniPath
 IniWrite, %Value%, %IniPath%, %Section%, %Key%
 return %errorlevel%
}


GetControl(ControlID)
{
 GuiControlGet, Value, , %ControlID%
 return %Value%
}


GetIni(Section, Key)
{
 global IniPath
 IniRead, Value, %IniPath%, %Section%, %Key%
 return Value
}


SetMyTimer(label, byref TimerArray, Period = 250, Priority = 0)
{
 ;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
 ;msgbox, Label: %Label%`nTimerArray: %TimerArray%
 SetTimer, %Label%, %Period%, %Priority%
 TimerArray = %A_TickCount%|%Period%
}


GetMyTimer(TimerArray, Mode = 3)
{
;http://www.autohotkey.com/forum/viewtopic.php?p=282254#282254
;Modes: 1 = Return total time, 2 = Return elapsed time, 3 = Return remaining time
 StringSplit, TimerArray, TimerArray, |
 if (TimerArray1  = "Off")
 {
  TimerArray2 := ""
  ElapsedTime := ""
  RemainingTime := ""
 }
 else
 {
  ElapsedTime := A_TickCount - TimerArray1
  RemainingTime := TimerArray2 - ElapsedTime
 }
 StringLower, mode, mode
 if mode = 1
    return TimerArray2
 else if mode = 2
  return ElapsedTime
 else if mode = 3
  return RemainingTime
 else
  return 1 ;Error. Unexpected value for mode
}


PlaySound(FileName)
{
;Trubbleguy http://www.autohotkey.com/forum/viewtopic.php?p=231332#231332
 global SoundPath
 run, %A_ScriptDir%\PlaySound.exe "%SoundPath%\%Filename%"
}


Also note that when compiling you can password protect the EXE and choose a custom icon.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey and 59 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