- Sleep, Hibernate, Shut down with canceling possibility
- Hour or Time from now (Snooze) ; both inputs update eachother
- Traytip
- Tooltip with update (to check how long remaining)
- Some text to remember
Don't forget to update the sound file!
Code: Select all
;_________________Alarm by e-motiv.net
; TODO: Use text file in case of failure/ahk shutdown etc.. (iniwrite or so) ?
; TODO: Make better representation of different time ranges in tooltip
AlarmShutdown:
if (TShut = 3)
Shutdown, 9
else ;Hibernate or Suspend
DllCall("PowrProf\SetSuspendState", "int", TShut = 2?1:0, "int", 0, "int", 0)
return
AlarmEnd:
SetTimer, AlarmEnd, Off
SetTimer, AlarmIconTipUpdate, Off
if TShut
{
SoundPlay, C:\Users\Ruben\Sounds\140 Grime Synth D 01.wav
WhichShut := TShut=3?"Shutdown":(TShut=2?"Hibernate":"Suspend")
Menu,TRAY, Tip, %WhichShut% in 20 seconds. Trigger alarm again to cancel. `n %AlarmText%
TrayTip,, %WhichShut% in 20 seconds. Trigger alarm again to cancel. `n %AlarmText%
SetTimer, AlarmShutdown, -20000
}
else
{
NewIconTip := RegExReplace(A_IconTip, "\n*--[\s\S]*--", "")
Menu,TRAY, Tip, %NewIconTip%
GoSub Alarm
}
return
Alarm:
if TShut
{
SetTimer, AlarmShutdown, Off ; Cancel shutdown
TShut = 0
TrayTip,, %WhichShut% cancelled.
Menu,TRAY, Tip
}
SoundPlay, C:\Users\Ruben\Sounds\140 Grime Synth D 01.wav
IfWinNotExist, Alarm ahk_class AutoHotkeyGUI
{
gui, +AlwaysOnTop -Border
gui, font, s10, Verdana
gui, add, text,ym+10 Center Section, Snooze:
gui, font, s20, Verdana
gui, add, edit,xm+70 ym W45 R1 Center Number Limit2 gAlarmChangeTime vTHours, % THours?THours:00
gui, add, text,x+2 yp+7, h
gui, add, edit,x+7 ym W45 R1 Center Number Limit2 gAlarmChangeTime vTMins, % TMins?TMins:00
gui, add, text,x+2 , '
gui, add, edit,x+5 ym W45 R1 Center Number Limit2 gAlarmChangeTime vTSecs, % TSecs?TSecs:00
gui, add, text,x+2 , ''
gui, font, s10, Verdana
gui, add, text,xm y+30, Untill:
gui, font, s20, Verdana
Gui, Add, DateTime,xm+70 yp-10 W160 Center gAlarmChangeSnooze vTTime, Time
gui, font, s10, Verdana
gui, Add, Edit, xm y+20 w300 R4 -VScroll vAlarmText, % AlarmText
Gui, Add,Radio, xm+10 y+20 vTShut, Sleep
Gui, Add,Radio, xp+80 yp, Hibernate
Gui, Add,Radio, xp+90 yp, Shut down
Gui, Add, Button,xm y+20 Center W300 R2 Default, Set!
}
; Fill in DateTime
GoSub AlarmChangeTime
gui, show, Restore, Alarm ;%A_Now%
return
AlarmChangeTime:
GuiControlGet,CF, FocusV
IfEqual, CF, TTime, Return ; Don't loop since edit g-label gets triggered by script (AlarChangeSnooze)
;MsgBox CurrentFocus: %CF%, A_Gui, A_GuiControl, A_GuiControlEvent, A_GuiEvent, A_EventInfo : %A_Gui%, %A_GuiControl%, %A_GuiControlEvent%, %A_GuiEvent%, %A_EventInfo%
;todo: add time functions here as unpossible times become possible (25:61:61)
GuiControlGet,THours
GuiControlGet,TMins
GuiControlGet,TSecs
Temp:=A_Now
Temp += %THours%,h
Temp += %TMins%,m
Temp += %TSecs%,s
GuiControl,,TTime,%Temp%
return
AlarmChangeSnooze:
GuiControlGet,TTime
TTime -= ,s
Temp2:=TTime // (60*60)
;MsgBox %TTime%, %Temp2%
GuiControl,,THours,%Temp2%
Temp2:=Mod(TTime,60*60) // 60
GuiControl,,TMins,%Temp2%
Temp2:=Mod(Mod(TTime,60*60),60)
GuiControl,,TSecs,%Temp2%
return
AlarmIconTipUpdate:
;Add icontip
;MSgBox %TTimeIUpdate% %TLeft% %A_IconTip%
TLeft-=%TTimeIUpdate%
TLeftHMS:=TLeft // (1000*60*60) . "h " . Mod(TLeft,1000*60*60) // (1000*60) . "m " . Mod(Mod(TLeft,1000*60*60),1000*60) // 1000 . "s"
TTimeText2:= " -- Alarm -- `n"
. " " . (AlarmText ? AlarmText . "`n" : "")
. " " . FTime . "`n"
. " " . TLeftHMS . " from now (± " . (TTimeIUpdate//1000) . " sec.) `n"
. " -- -- "
NewIconTip := RegExReplace(A_IconTip, " -- Alarm --[\s\S]* -- -- ", TTimeText2, Replaced)
If !Replaced
NewIconTip := A_IconTip . (A_IconTip=""?"":"`n") . TTimeText2
;MsgBox Old: %A_IconTip%`nReplaced: %Replaced%`nNew: %NewIconTip%
Menu,TRAY, Tip, %NewIconTip%
return
ButtonSet!:
Gui, Submit
Gui, Destroy
TStart:=A_Now
TLeft:=((THours*60 + TMins)*60+TSecs)
TTimeIUpdate:=TLeft//20*1000 ; Distribute updater, but min. 1 sec.
TLeft*=1000
;MsgBox %THours%%TMins%%TSecs%
;// Set one-time alarm timer
SetTimer, AlarmEnd, %TLeft%
TTimeText:=THours . "h " . TMins . "m " . TSecs . "s"
FormatTime, FTime, TTime, HH : mm : ss
TrayTip,, Alarm Set for `n %FTime% `n %TTimeText% from now
;//Set repeating icontip-update timer
GoSub AlarmIconTipUpdate ; For icontip
SetTimer, AlarmIconTipUpdate, %TTimeIUpdate%
return
GuiEscape:
GuiClose:
Gui, Destroy
return