Countdown Timer

Post your working scripts, libraries and tools for AHK v1.1 and older
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Countdown Timer

25 Feb 2021, 17:00

This is just a basic functional countdown timer. Couldn't find one that did what I wanted so made my own.

Code: Select all

 
 #NoEnv
Gui, Timer:Show, w165 h130, Timer 
Gui , Timer:+AlwaysOnTop +ToolWindow 

Gui , Timer:Font, s10, arial
Gui , Timer:Add, Edit, x0 y16 w55 h20 center ve3,
Gui , Timer:Add, UpDown, x0 y16 w55 h20 -VScroll, 0
Gui , Timer:Add, Edit,  x55 y16 w55 h20 center ve2,
Gui , Timer:Add, UpDown, x55 y16 w55 h20 -VScroll, 0
Gui , Timer:Add, Edit,  x110 y16 w55 h20 center ve1,
Gui , Timer:Add, UpDown, x110 y16 w55 h20 -VScroll, 10

Gui, Timer:add, DateTime, vTStart x1 y110 , Time

Gui, Timer:Add, Button, gstart x0 y41 w80 h22 center, Re/Start
Gui, Timer:Add, Button, gresume x80 y41 w85 h22 center, P/Resume
Gui , Timer:add, Text, x0 y1 w55 center, Hours
Gui , Timer:add, Text, x55 y1 w55 center, Minutes
Gui , Timer:add, Text, x110 y1 w55 center, Seconds

Gui, Timer:Font, s28 c3a39c0 
Gui, Timer:add, text , x0 y65 w170 h40 center vdispt, c/d timer
return

start:		
  Pause, 0
  Gui, Submit, NoHide
 If e3 is not number
	e3:=0
 If e2 is not number
	e2:=0
 If e1 is not number
	e1:=0
   secsLeft :=  e3*3600+e2*60+e1
   seconds := Format("{:02}" , floor(mod(secsLeft , 60)))	
   minutes := Format("{:02}" , mod(floor(secsLeft/60) , 60))
   hours  :=  floor(secsLeft/3600)
   
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   GuiControl, Timer:text , dispt, %hur%:%min%:%sec% 
	
   FormatTime, TimeString, , hh:mm:ss t
   GuiControl, Timer:text , TStart, %TimeString%'M '
   SetTimer, CDTimer, 1000
return

resume:
  Pause, Toggle, 1
  GuiControl , , e3, %hours%
  GuiControl , , e2, %minutes%
  GuiControl , , e1, %seconds%
  GuiControl, , dispt, %hur%:%min%:%sec%
return

 CDTimer:
  secsLeft--
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
    GuiControl, Timer:text , dispt, %hur%:%min%:%sec%
  IfLess, secsLeft, 1
  {
    SetTimer CDTimer, Off
  ; do stuff
  ; SoundBeep, 360, 3800
  ; run music.mp3
  ; run audio.midi
  ; make coffee
  ; msgbox Time's Up !
    return
 ExitApp
  }
  Else	
Return

TimerGuiClose:
ExitApp
Attachments
cdTimer.gif
cdTimer.gif (4.64 KiB) Viewed 5901 times
Last edited by fstoldr on 07 Mar 2021, 20:38, edited 1 time in total.
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

01 Mar 2021, 16:17

This adds options to a drop down menu: open file, system beep, message box, sleep or shutdown.
timer2.png
timer2.png (9.04 KiB) Viewed 5867 times

Code: Select all

#NoEnv

Gui , Timer : Show , w165 h140 , Timer
;Gui , Timer : Show , w265 h230 , Timer
Gui , Timer:+AlwaysOnTop +ToolWindow 

Gui , Timer:Font , s10 , Trebuchet MS
Gui , Timer:Add , Edit , x0 y16 w55 h20 center ve3
Gui , Timer:Add , UpDown , x0 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x55 y16 w55 h20 center ve2
Gui , Timer:Add , UpDown , x55 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x110 y16 w55 h20 center ve1
Gui , Timer:Add , UpDown , x110 y16 w55 h20 -VScroll , 10

Gui , Timer:add, text , vTStart x1 y120 w58 ,             
Gui, Timer:Add, DropDownList, vtimer_options Choose1 altsubmit x60 y110 w110 gset_option_func, no option|open file|system beep|message box|hybernate/sleep|shutdown

Gui , Timer:Add , Button , gstart x0 y41 w80 h22 center , Re/Start
Gui , Timer:Add , Button , gresume x80 y41 w85 h22 center , P/Resume
Gui , Timer:add , Text , x0 y0 w40 center , Hrs
Gui , Timer:add , Text , x55 y0 w40 center , Min
Gui , Timer:add , Text , x110 y0 w40 center , Sec

Gui , Timer:Font , s26 cBlue , Segoe UI
Gui , Timer:add , text , x0 y62 w169 h38 center vdispt , C/D Timer
return

start:
   Pause , 0
   Gui , Submit , NoHide
   
   Gui , Timer:Font , s26 cBlue , Segoe UI
   GuiControl , Timer:Font , dispt
 If e3 is not number
	e3:=0
 If e2 is not number
	e2:=0
 If e1 is not number
	e1:=0
   secsLeft :=  e3*3600+e2*60+e1
   seconds := Format("{:02}" , floor(mod(secsLeft , 60)))	
   minutes := Format("{:02}" , mod(floor(secsLeft/60) , 60))
   hours  :=  floor(secsLeft/3600)
   
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   
   GuiControl , Timer:text , dispt , %hur%:%min%:%sec% 
   
   FormatTime , TimeString, , HH:mm:ss
   GuiControl , Timer:text , TStart , %TimeString%
   SetTimer , CDTimer , 1000
return

resume:
   Pause , Toggle , 1
   GuiControl , , e3 , %hours%
   GuiControl , , e2 , %minutes%
   GuiControl , , e1 , %seconds%
   GuiControl , , dispt , %hur%:%min%:%sec%
return

CDTimer:
;   Gui , Submit , NoHide
   secsLeft--
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   GuiControl , Timer:text , dispt, %hur%:%min%:%sec%
   IfEqual , secsLeft , 0
   {
      Gui , Timer:Font , s26 cRed ; Segoe UI
      GuiControl , Timer:Font , dispt  
      goto  opb%timer_options%
      return
   }
   Else	
      Return
   
set_option_func:
   Gui , Submit , NoHide
   goto  opa%timer_options%
opa1:
opb1:
return

opa2:
	FileSelectFile, SelectedFile, 3, , Open a file, Open After Countdown (*.*)
return
opb2:
	run, %SelectedFile%
return
   
opb3:
	 SoundBeep, 360, 3800
opa3:
return

opb4:
   msgbox , 262144 , Timer, Time's Up !
opa4:
return

opb5:
   run, rundll32.exe powrprof.dll`,SetSuspendState Sleep
opa5:
return

opb6:
   run, shutdown.exe /s
opa6:
return

TimerGuiClose:
ExitApp
Last edited by fstoldr on 07 Mar 2021, 20:40, edited 2 times in total.
sooyke_
Posts: 25
Joined: 18 Nov 2020, 10:27

Re: Countdown Timer

05 Mar 2021, 07:56

954.png
954.png (4.65 KiB) Viewed 5775 times


Nice but some typing error :)
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

05 Mar 2021, 17:56

@sooyke_

Thanks for the correction. I updated my script.
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

06 Mar 2021, 16:05

This adds tooltips, more clickable things and an option to set a countdown after computer is idle for some time. So with this option there will be 2 countdowns, first counting to when the computer has been idle the designated time then the timer will countdown the selected time.
idlecdt.gif
idlecdt.gif (8.1 KiB) Viewed 5616 times

Code: Select all

#NoEnv

rscrn := A_ScreenWidth-300

Gui , Timer:Show , w165 h140 X%rscrn% Y0, Timer
Gui , Timer: +hwndguiId +AlwaysOnTop +ToolWindow 
Gui , Timer:Font , s10 , Trebuchet MS						
;	===========================================================
Gui , Timer:add , Text , x0 y0 w40 center , Hrs
Gui , Timer:add , Text , x55 y0 w40 center , Min
Gui , Timer:add , Text , x110 y0 w40 center , Sec
;	===========================================================
Gui , Timer:Add , Edit , x0 y16 w55 h20 center ve3
Gui , Timer:Add , UpDown , x0 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x55 y16 w55 h20 center ve2
Gui , Timer:Add , UpDown , x55 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x110 y16 w55 h20 center ve1,
Gui , Timer:Add , UpDown , x110 y16 w55 h20 -VScroll , 10
;	===========================================================
Gui , Timer:Add , Button , gstart x0 y41 w80 h22 center vbStart, Re/Start
bStart_TT := "start countdown timer"
Gui , Timer:Add , Button , gresume x80 y41 w85 h22 center vbPause, P/Resume
bPause_TT := "pause or resume countdown timer"
;	===========================================================
Gui , Timer:add, text , vTIdle x1 y105 w58 gopa7 , 00:00:00     
Tidle_TT := "PC idle time before auto countdown - 0 to disable"
Gui , Timer:add, text , vTStart x1 y120 w58 gSTTTT,
TStart_TT := "This is the time the timer last started."  
;	===========================================================   
Gui, Timer:Add, DropDownList, vtimer_options Choose1 altsubmit x60 y113 w104 gset_option_func, No_option|Open File|System Beep|Message Box|Hybernate/Sleep|Shutdown|Start_After_Idle
timer_options_TT := "Select action to take."
;	===========================================================
Gui , Timer:Font , s26 cBlue , Segoe UI
Gui , Timer:add , text , x0 y62 w169 h38 center vdispt gresume, C/D Timer
dispt_TT := "Time remaining on countdown"
;	===========================================================
OnMessage(0x200, "MsMoveTTP")      
OnMessage(0x2A1, "HoverTTP") 
return

MsMoveTTP(wParam, lParam, msg, hwnd)
	{
	static TrackPos
	 if (TrackPos = lParam)
	 return
	TrackPos := lParam	
	tooltip
	cbSize:=(A_PtrSize+4)*2
	VarSetCapacity(TrkMEvnt, cbSize,0)
	NumPut(cbSize, TrkMEvnt, 0, "Uint")
	NumPut(3, TrkMEvnt, 4, "Uint")
	NumPut(hwnd, TrkMEvnt, 8, "Ptr")
	NumPut(800, TrkMEvnt, A_PtrSize+8, "Uint")
	DllCall("User32.dll\TrackMouseEvent", "uint", &TrkMEvnt)
	}
STTTT:
return
HoverTTP()
	{
	tooltip % %A_GuiControl%_TT
	}
return

start:
   Tog:=1
   Gui , Submit , NoHide
   Gui , Timer:Font , s26 cBlue , Segoe UI
   GuiControl , Timer:Font , dispt
	e3 := round(e3,3)
	e2 := round(e2,3)
	e1 := round(e1,3)
   secsLeft :=  e3*3600+e2*60+e1
   seconds := Format("{:02}" , floor(mod(secsLeft , 60)))		;entry field
   minutes := Format("{:02}" , mod(floor(secsLeft/60) , 60))	
   hours  :=  floor(secsLeft/3600)								
   
   hur := Format("{:02}" , floor(abs(secsleft)/3600))			;display
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   
   GuiControl , Timer:text , dispt , %hur%:%min%:%sec% 
   FormatTime , TimeString, , HH:mm:ss				 
   GuiControl , Timer:text , TStart , %TimeString%
   SetTimer , CDTimer , 1000
return

resume:
  if (hours+minutes+seconds < -1)
	goto start
	else SetTimer, CDTimer, % (Tog:=!Tog) ? "on":"off"
   GuiControl , , e3 , %hours%
   GuiControl , , e2 , %minutes%
   GuiControl , , e1 , %seconds%
   GuiControl , , dispt , %hur%:%min%:%sec%
return

CDTimer:
   secsLeft--
   hur := Format("{:02}" , floor(abs(secsleft)/3600))			;display
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   GuiControl , Timer:text , dispt, %hur%:%min%:%sec%
   secsLeft:=floor(secsleft)
   Ifequal, secsLeft,0
	{
	Gui , Timer:Font , s26 cRed , Segoe UI
	GuiControl , Timer:Font , dispt  
	goto  opb%timer_options%
	return
	}
   Else	
      Return
   
set_option_func:
   Gui , Submit , NoHide
   goto  opa%timer_options%
opa1:
opb1:
return

opa2:
	FileSelectFile, SelectedFile, 3, , Open a file, Open After Countdown (*.*)
return
opb2:
	run, %SelectedFile%
return
   
opb3:
run %A_WinDir%\Media\alarm01.wav
opa3:
return

opb4:
   msgbox , 262144 , Timer, Time's Up !
opa4:
return

opb5:
   run, rundll32.exe powrprof.dll`,SetSuspendState Sleep
opa5:
return

opb6:
   run, shutdown.exe /s
opa6:
return

Check4Idle:
;   Gui , Submit , NoHide
;tooltip %A_TimeIdle%
if (IdleTCd < 1)
{
settimer Check4Idle, off
return
}
If (A_TimeIdle > IdleTCd*1000)
	{
	SetTimer Check4Idle, Off
	IdleTCd:=0
	goto start
	}
return

opa7: 
   Gui , Submit , NoHide
   inputbox, IdleTCd, Idle Time , Please enter minutes for PC to idle before auto countdown. 0 to disable, ,180 ,160
    idlhur := Format("{:02}" , floor(abs(IdleTCd)/60))
	idlmin := Format("{:02}" , floor(mod(abs(IdleTCd), 60)))
	idlsec := Format("{:02}" , floor(mod(abs(IdleTCd*60), 60)))
	IdleTCd := floor(IdleTCd*60)
    SetTimer , Check4Idle , 1000
	GuiControl , Timer:text , TIdle , %idlhur%:%idlmin%:%idlsec%
opb7:
return 

TimerGuiClose:
ExitApp
Last edited by fstoldr on 12 Mar 2021, 13:30, edited 7 times in total.
sooyke_
Posts: 25
Joined: 18 Nov 2020, 10:27

Re: Countdown Timer

07 Mar 2021, 03:30

964.png
964.png (7.99 KiB) Viewed 5582 times
Some remarks i found when using the timer but i can be because of my system and not an universal problem :

the tooltip stays visible if you move to quickly leaving the window
the window is difficult to move there is almost no place in the titlebar to drag from ( i added " Timer:+AlwaysOnTop +ToolWindow ")
the dropdown control is not completely in the window , it is a minor thing but i made it smaller

Thanks for sharing , usefull tool :)
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

07 Mar 2021, 10:38

@sooyke_
Thank you for the suggestions. I updated my script. The first one I am aware of but not sure of a good solution. The mouse detection seems to only work over the gui window. If it misses the edge it doesn't work. Maybe there's a way to add an invisible gui layer as a border for extra mouse detection? I don't know.

edit: fixed the sticking tooltip by blanking 5 pixels near the edge
sooyke_
Posts: 25
Joined: 18 Nov 2020, 10:27

Re: Countdown Timer

08 Mar 2021, 07:51

Your solution works quite well :)

There is another one but it seems overkill in this situation but it works flawless ( thanks Helgef ) in the example and maybe interesting to know .

https://www.autohotkey.com/boards/viewtopic.php?f=5&t=34879

p.s. maybe it is easier when you edit your post to make it clear which code is the updated one or update all code .

Greetings
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

09 Mar 2021, 18:21

I adjusted the tooltips so they have a delayed popup and mostly don't stick but if they do they get blanked after a short timer.

This is all the tooltip stuff. Seems like I might have overkilled it a bit but oh well.
Spoiler
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: Countdown Timer

11 Mar 2021, 16:11

thank you for this script. It will be useful. :clap:
For my part, I have completely removed the tooltip help. Not very useful because most of the buttons are self-explanatory. :problem:
I also reorganized the GUI to my taste.

The window can shrink itself when you click on the upper left corner to hide all the buttons.

Code: Select all


fsize:=32

#NoEnv
Gui , Timer : -dpiscale
Gui , Timer :  +AlwaysOnTop -dpiscale +resize +toolwindow +LastFound

Gui, Timer:Default

Gui , Timer:add , text , x0 y0  w20 h20 gtog +backgroundtrans ,
Gui , Timer:add , text , x0 y0  w20 h20 gstart vires +backgroundtrans -border ,

Gui , Timer:Font , s%fsize% cBlue , Impact
Gui , Timer:add , text , x8 yp  h38 left  vdispt gresume, 00:00:00
Gui , Timer:Font
Gui , Timer:Font , s10 , Trebuchet MS

;	===========================================================
Gui , Timer:Add , Button , % "gstart x4 y+2 h22 center vbStart w83"  , Re/Start
Gui , Timer:Add , Button , % "gresume x+2 yp h22 vbres center w83" , P/Resume
;	===========================================================

;	===========================================================
Gui , Timer:add , Text , x4 y+2 w55 -border center , Hrs
Gui , Timer:add , Text , x+1 yp w55 -border center , Min
Gui , Timer:add , Text , x+1 yp w57 -border center , Sec
;	===========================================================

;	===========================================================
Gui , Timer:Font , s10 , Trebuchet MS
Gui , Timer:Add , Edit , x4 y+2 w55 h20 center ve3
Gui , Timer:Add , UpDown ,  yp w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x+2 yp w55 h20 center ve2
Gui , Timer:Add , UpDown ,   w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x+2 yp w55 h20 center ve1
Gui , Timer:Add , UpDown ,  w55 h20 -VScroll vud, 10

;	===========================================================
Gui , Timer:add, text , vTIdle x4 y+3 -border w58 gopa7 section , 00:00:00     
Gui , Timer:add, text , vTStart x4 y+2 w58 -border gSTTTT,  00:00:00
;	===========================================================

Gui, Timer:Add, DropDownList, vtimer_options Choose1 altsubmit x+2 ys+10 w110 gset_option_func, no_option|open file|system beep|message box|hybernate/sleep|shutdown|start_after_idle

STTTT:

Gui, Show, % " w" getcontrol("bres", "xw")+2 " h" getcontrol("timer_options", "yh")+2, Countdown Timer

GuiControl, Movedraw, ires, % " x0 " "y " getcontrol("dispt", "yh")-20


return
ires:
return
tog:
toggleb:=!toggleb

if toggleb {
Gui, Show, % " w" getcontrol("dispt", "xw")+4 " h" getcontrol("bres", "y")
}
else
Gui, Show, %  " w" getcontrol("ud", "xw")+4 " h" getcontrol("timer_options", "yh")+2

return

start:
;   Pause , 0
   Toggle:=1
   Gui , Submit , NoHide
   ;Gui , Timer:Font , s26 cBlue , Segoe UI
   Gui , Timer:Font , s%fsize% cBlue , Impact
   GuiControl , Timer:Font , dispt
 If e3 is not number
	e3:=0
 If e2 is not number
	e2:=0
 If e1 is not number
	e1:=0
 
   secsLeft :=  e3*3600+e2*60+e1
   seconds := Format("{:02}" , floor(mod(secsLeft , 60)))	
   minutes := Format("{:02}" , mod(floor(secsLeft/60) , 60))
   hours  :=  floor(secsLeft/3600)
   
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   
   GuiControl , Timer:text , dispt , %hur%:%min%:%sec% 
   FormatTime , TimeString, , HH:mm:ss				 
   GuiControl , Timer:text , TStart , %TimeString%
   SetTimer , CDTimer , 1000
return

resume:
  if (hours+minutes+seconds < -1) {
  gosub start
  return
  }
	Toggle:=!Toggle
	if (toggle) {  
		SetTimer, CDTimer, on
	 }
    else
		SetTimer, CDTimer, off
   GuiControl , , e3 , %hours%
   GuiControl , , e2 , %minutes%
   GuiControl , , e1 , %seconds%
   GuiControl , , dispt , %hur%:%min%:%sec%
return

CDTimer:
;   Gui , Submit , NoHide
   secsLeft--
   hur := Format("{:02}" , floor(abs(secsleft)/3600))
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   GuiControl , Timer:text , dispt, %hur%:%min%:%sec%
   IfEqual , secsLeft , 0
   {
      ;Gui , Timer:Font , s26 cRed , Segoe UI
      Gui , Timer:Font , s%fsize% cRed , Impact
      GuiControl , Timer:Font , dispt  
      goto  opb%timer_options%
      return
   }
   Else	
      Return
   
set_option_func:
   Gui , Submit , NoHide
   goto  opa%timer_options%
opa1:
opb1:
return

opa2:
	FileSelectFile, SelectedFile, 3, , Open a file, Open After Countdown (*.*)
return
opb2:
	run, %SelectedFile%
return
   
opb3:
	 SoundBeep, 360, 1000
opa3:
return

opb4:
   msgbox , 262144 , Timer, Time's Up !
opa4:
return

opb5:
   run, rundll32.exe powrprof.dll`,SetSuspendState Sleep
opa5:
return

opb6:
   run, shutdown.exe /s
opa6:
return

Check4Idle:
	if (IdleTCd < 1){
    SetTimer Check4Idle, Off
	return
	}
	If (A_TimeIdle > IdleTCd*1000){
    SetTimer Check4Idle, Off
	gosub start
	return
	}
return

opa7: 
   Gui , Submit , NoHide
   inputbox, IdleTCd, Idle Time , Please enter minutes for PC to idle before auto countdown. 0 to disable, ,180 ,160
   SetTimer , Check4Idle , 1000
    idlhur := Format("{:02}" , floor(abs(IdleTCd)/60))
	idlmin := Format("{:02}" , floor(mod(abs(IdleTCd), 60)))
	idlsec := Format("{:02}" , floor(mod(abs(IdleTCd*60), 60)))
	IdleTCd := floor(IdleTCd*60)
	
	GuiControl , Timer:text , TIdle , %idlhur%:%idlmin%:%idlsec%
opb7:
return 

TimerGuiClose:
ExitApp


getcontrol(crtname, what)
{
 guicontrolget, out,  Pos, %crtname%

 if (what="x")
 return % outx

 if (what="y")
 return % outy

 if (what="w")
 return % outW

 if (what="h")
 return % outH

 if (what="yh")
 return % outy + outH 

 if (what="xw")
 return % outx + outW
}

image.png
image.png (3.29 KiB) Viewed 5332 times
Attachments
image.png
image.png (8.42 KiB) Viewed 5332 times
Last edited by SpeedMaster on 28 Feb 2023, 15:32, edited 1 time in total.
fstoldr
Posts: 20
Joined: 25 Feb 2021, 16:31

Re: Countdown Timer

12 Mar 2021, 09:03

@SpeedMaster
Ooh that looks nice. Makes me wanna fancy mine up but I doubt it would be able to compete.

The tooltips are probably not necessary but became a personal challenge. On that note I think I got them working properly without using a timer by using an example by Lexikos.
Track Mouse Hover

This is the tooltip section now.
Spoiler
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: Countdown Timer

16 Mar 2021, 06:42

Thanks, this is another countdown timer script from my archive that I use frequently:

Code: Select all

; http://www.autohotkey.com/forum/topic71384.html
; Multiple CountDown Timer Utility

; SmartCountDownTimer.ahk - Multiple Countdown timer with sound alerts
; Tested with AutoHotkey 1.0.92.02

path := "C:\...\Sound Effects"

#SingleInstance Off ; Allow multiple instances
#NoTrayIcon
#NoEnv

cd_IniFile := A_ScriptDir "\CountDown.ini"

; Read settings from INI file
IniRead cd_Duration, %cd_IniFile%, Main, Duration, %A_Space%
IniRead cd_PlaySound, %cd_IniFile%, Main, PlaySound, %True%
IniRead cd_SoundFile, %cd_IniFile%, Main, SoundFile, %A_ScriptDir%\

gui, font, s18, Arial, cBlack, w700 

Gui, Color , 00FFFF, 00FFFF

; Generated using SmartGUI Creator 4.0
Gui, Add, Text, cBlack x30 y5 w100 h40;h30 , Message:
Gui, Add, Edit, cBlack x30 y35 w415;w430 h40;h30 vcd_Message,
Gui, Add, Text, cBlack x30 y80 w100 h40 , &Hours:
Gui, Add, Edit, cBlack x30 y110 w98 h40 Number vcd_HoursEdit gTimeEdited, % cd_Duration // 3600
Gui, Add, Text, cBlack x130 y80 w100 h40 , &Minutes:
Gui, Add, Edit, cBlack x130 y110 w98 h40 Number vcd_MinutesEdit gTimeEdited, % mod(cd_Duration, 3600) // 60
Gui, Add, Text, cBlack x230 y80 w100 h40 , S&econds:
Gui, Add, Edit, cBlack x230 y110 w100;w98 h40 Number vcd_SecondsEdit gTimeEdited, % mod(cd_Duration, 60)
Gui, Add, Text, cBlack x30 y166 w415;w410 h40 vcd_DurationText,
Gui, Add, Checkbox, x30 y200 w450 h40 vcd_PlaySoundCheckBox, &Play sound at the end of countdown
GuiControl,, cd_PlaySoundCheckBox, %cd_PlaySound%
Gui, Add, Button, x30 y256 w150 h40;h42 gSoundFileBrowse, Sound &file:
Gui, Add, Edit, cBlack x30 y316 w415 h40 vcd_SoundFileEdit, %cd_SoundFile%
Gui, Add, Button, x375.5;x255 y256 w70 h40;h42 gPlayFinishSound, &Test
Gui, Add, Button, x30 y380 w415 h40;h50 vcd_Button gCountDownPress Default, &Start (Press Enter)
Gui, Add, Text, x30 y440;y450 w415;w430 h40;h50, Alt+c for another timer. Esc to close
Gosub TimeEdited
Gui, Show, x131 y91 h500 w472, CountDown
Gui +LastFound
cd_Gui := WinExist() ; Remember Gui window ID
Return

CountDownPress:
GuiControlGet yourmessage,, Edit1
; msgbox your message is %yourmessage%
GuiControlGet cd_ButtonCaption,, cd_Button
if cd_ButtonCaption = &STOP ; Compare button text
{
  SetTimer CountDownTimer, Off
  WinSetTitle ahk_id %cd_Gui%,, CountDown
  GuiControl,, cd_Button, &START
  Return
}
cd_Duration := GetDurationInSec()
if cd_Duration <= 0
{
  MsgBox 16, Error, Invalid time.
  Return
}
WinSetTitle ahk_id %cd_Gui%,, %cd_Duration% (%yourmessage%) ; Refresh tray button text
GuiControl,, cd_Button, &STOP
SetTimer CountDownTimer, 1000
WinMinimize, A
Return

CountDownTimer:
GuiControlGet yourmessage,, Edit1
cd_Duration--
;WinSetTitle ahk_id %cd_Gui%,, %cd_Duration% (%yourmessage%) ; Refresh tray button text
;WinSetTitle ahk_id %cd_Gui%,, %cd_Duration% (Seconds) ; Refresh tray button text
r:=secsToStr(cd_Duration) ; Added 01/21/20
WinSetTitle ahk_id %cd_Gui%,, %r% << Remaining Time ; Refresh tray button text
if cd_Duration > 0
  Return

SoundPlay, %path%\alarm_clock.wav ; <<<<<<<<<<
yourmessage = %yourmessage% (Click me to dismiss)
 
NotifyID := Notify("Countdown Completed!",yourmessage,0) ; = lasts until clicked
  Sleep, 5000
 
Loop, 10
{
;   SoundBeep, 2300, 1000 ; 100
}
;MsgBox, 4128, Countdown, Countdown Completed! ; On top. No sound. Icon (info)
;MsgBox, 32, Countdown, Countdown Completed! ; Not on top. No sound. Icon (info)
MsgBox, 262208, Countdown, Countdown Completed! ; On top. Sound. Icon (info)
;MsgBox, 262144, Countdown, Countdown Completed! ; On top. Sound
Reload
;ExitApp

Gui Flash ; Flash the tray button
GuiControlGet cd_PlaySound,, cd_PlaySoundCheckBox
if cd_PlaySound ; Play sound if checked
  Gosub PlayFinishSound ; Let me hear that sound!
Gosub CountDownPress
Return

SoundFileBrowse:
FileSelectFile cd_SoundFile, 1, %cd_SoundFile% ; Open file selection dialog
if cd_SoundFile
  GuiControl,, cd_SoundFileEdit, %cd_SoundFile%
Return

PlayFinishSound:
GuiControlGet cd_SoundFile,, cd_SoundFileEdit ; Get filename
IfExist %cd_SoundFile%
  SoundPlay %cd_SoundFile%
Return

TimeEdited: ; Update duration text
GuiControl,, cd_DurationText, % "Duration: " GetDurationInSec() " seconds"
Return

GetDurationInSec()
{
local Hours, Minutes, Seconds
GuiControlGet Hours,, cd_HoursEdit
if ! Hours
Hours := 0
GuiControlGet Minutes,, cd_MinutesEdit
if ! Minutes
Minutes := 0
GuiControlGet Seconds,, cd_SecondsEdit
if ! Seconds
Seconds := 0
Return Hours * 3600 + Minutes * 60 + Seconds
}

!c::
; WinActivate ahk_id %cd_Gui%
; Run, %A_ScriptDir%\SmartCountDownTimer.exe
Run, G:\Documents and Settings\NA\My Documents\AutoHotkey\Multiple CountDown Timer.ahk
; Run %comspec% /c %A_ScriptDir%\SmartCountDownTimer.exe
Return

GuiEscape:
GuiClose: ; Close window, save settings to INI file
GuiControlGet cd_PlaySound,, cd_PlaySoundCheckBox
GuiControlGet cd_SoundFile,, cd_SoundFileEdit
IniWrite % GetDurationInSec(), %cd_IniFile%, Main, Duration
IniWrite %cd_PlaySound%, %cd_IniFile%, Main, PlaySound
IniWrite %cd_SoundFile%, %cd_IniFile%, Main, SoundFile
Gui, Submit ; Save each control's contents to its associated variable.
ExitApp ; Exit from script
Return

;
; Notify() 0.45 made by gwarble - sept 09
; multiple tray area notifications
; thanks to Rhys/engunneer/HugoV/Forum Posters
;
; Notify([Title,Message,Duration,Options,Image])
;
;     Title      [!!!]          "" to omit title line
;     Message      []           "" to omit message line
;     Duration    [15]          seconds to show notification
;                               0 to flash until clicked
;                               <0 to ExitApp on click/timeout
;                               "-0" for permanent and exitOnClick
;     Options                   string of options... see function
;          [SI=999 GC=Blue...]  most options are remembered (static)
;                               "Reset" to restore default options
;                               if you want to show as well, use NO=Reset
;                               "Wait" to wait for a notification ***
;     Image []                  Image file name/library or
;                               number of icon in shell32.dll
;                               Gui Number to "Wait" for ***
;
;     Return                    Gui Number used  ***
;                               0 if failed (too many open)
;

Notify(Title="Time's up !",Message="Time's up ! - Click me to dismiss",Duration=30,Options="",Image="")
{
 Static                ; Options string: "TS=12 GC=Blue..."
 static GF := 50       ;    Gui First Number  ; = override Gui: # used
 static GL := 74       ;    Gui Last Number   ; = between GF and GL
 static GC := "FFFFAA" ;    Gui Color         ; ie: don't use GF<=Gui#<=GL
 static GR := 9        ;    Gui Radius        ; elsewhere in your script
 static GT := "Off"    ;    Gui Transparency
 static TS := 14       ;  Title Font Size
 static TW := 625      ;  Title Font Weight
 static TC := "Black"  ;  Title Font Color
 static TF := "Lucida Console" ; Title Font Face
 static MS := 14       ; Message Font Size
 static MW := 550      ; Message Font Weight
 static MC := "Black"  ; Message Font Color
 static MF := "Lucida Console" ; Message Font Face
 static BC := "000000" ; Border Colors
 static BW := 2        ; Border Width/Thickness
 static BR := 13       ; Border Radius
 static BT := 105      ; Border Transpacency
 static BF := 150      ; Border Flash Speed
 static SI := 350      ; Speed In (AnimateWindow)
 static SC := 100      ; Speed Clicked (AnimateWindow)
 static ST := 450      ; Speed TimeOut (AnimateWindow)
 static IW := 32       ; Image Width
 static IH := 32       ; Image Height
 static IN := 0        ; Image Icon Number (from Image)
 static AX := 0        ; Action X Close Button (maybe add yes/no ok/cancel, etc...)
 local AC, AT          ; Actions Clicked/Timeout
 local _Notify_Action, ImageOptions, GY, OtherY

_Notify_:
 local NO := 0         ; NO is Notify Option [NO=Reset]
 If (Options)
 {
  IfInString, Options, =
  {
   Loop,Parse,Options,%A_Space%
    If (Option:= SubStr(A_LoopField,1,2))
     %Option%:= SubStr(A_LoopField,4)
   If NO = Reset
   {
    Options := "GF=50 GL=74 GC=FFFFAA GR=9 GT=Off "
     . "TS=8 TW=625 TC=Black TF=Arial MS=8 MW=550 MC=Black MF=Arial "
     . "BC=Black BW=2 BR=9 BT=105 BF=150 SC=300 SI=250 ST=100 "
     . "IW=32 IH=32 IN=0"
    Goto, _Notify_
   }
  }
  Else If Options = Wait
   Goto, _Notify_Wait_
 }

 GN := GF
 Loop
  IfNotInString, NotifyList, % "|" GN
   Break
  Else
  If (++GN > GL)
    Return 0 ; too many notifications open!
 NotifyList .= "|" GN
 GN2 := GN + GL - GF + 1
 If AC <>
  ActionList .= "|" GN "=" AC

 Prev_DetectHiddenWindows := A_DetectHiddenWindows
 Prev_TitleMatchMode := A_TitleMatchMode
 DetectHiddenWindows On
 SetTitleMatchMode 1
 If (WinExist("NotifyGui")) ; find all Notifications from ALL scripts, for placement
  WinGetPos, OtherX, OtherY ; change this to a loop for all open notifications?
 DetectHiddenWindows %Prev_DetectHiddenWindows%
 SetTitleMatchMode %Prev_TitleMatchMode%

 Gui, %GN%:-Caption +ToolWindow +AlwaysOnTop -Border
 Gui, %GN%:Color, %GC%
 Gui, %GN%:Font, w%TW% s%TS% c%TC%, %TF%
 If (Image)
 {
  If FileExist(Image)
   Gui, %GN%:Add, Picture, w%IW% h%IH% Icon%IN%, % Image
  Else
   Gui, %GN%:Add, Picture, w%IW% h%IH% Icon%Image%, c:\windows\system32\shell32.dll
  ImageOptions = x+10
 }
 If Title <>
  Gui, %GN%:Add, Text, % ImageOptions, % Title
 Gui, %GN%:Font, w%MW% s%MS% c%MC%, %MF%
 If ((Title) && (Message))
  Gui, %GN%:Margin, , -5
 If Message <>
  Gui, %GN%:Add, Text,, % Message
 If ((Title) && (Message))
  Gui, %GN%:Margin, , 8
 Gui, %GN%:Show, Hide, NotifyGui
 Gui  %GN%:+LastFound
 WinGetPos, GX, GY, GW, GH

 If AX =
 {
  GW += 10
  Gui, %GN%:Font, w800 s6 c%MC%
  Gui, %GN%:Add, Text, % "x" GW-11 " y-1 Border Center w12 h12 g_Notify_Kill_" GN - GF + 1, X
 }

 Gui, %GN%:Add, Text, x0 y0 w%GW% h%GH% g_Notify_Action BackgroundTrans
 If (GR)
  WinSet, Region, % "0-0 w" GW " h" GH " R" GR "-" GR
 If (GT)
  WinSet, Transparent, % GT

 SysGet, Workspace, MonitorWorkArea
 NewX := WorkSpaceRight-GW-5
 If (OtherY)
  NewY := OtherY-GH-5
 Else
  NewY := WorkspaceBottom-GH-5
 If NewY < % WorkspaceTop
  NewY := WorkspaceBottom-GH-5

 Gui, %GN2%:-Caption +ToolWindow +AlwaysOnTop -Border +E0x20
 Gui, %GN2%:Color, %BC%
 Gui  %GN2%:+LastFound
 If (BR)
  WinSet, Region, % "0-0 w" GW+(BW*2) " h" GH+(BW*2) " R" BR "-" BR
 If (BT)
  WinSet, Transparent, % BT

 Gui, %GN2%:Show, % "Hide x" NewX-BW " y" NewY-BW " w" GW+(BW*2) " h" GH+(BW*2)
 Gui, %GN%:Show,  % "Hide x" NewX " y" NewY " w" GW, NotifyGui
 Gui  %GN%:+LastFound
 If SI
  DllCall("AnimateWindow","UInt",WinExist(),"Int",SI,"UInt","0x00040008")
 Else
  Gui, %GN%:Show, NA, NotifyGui
 Gui, %GN2%:Show, NA
 WinSet, AlwaysOnTop, On

 If ((Duration < 0) OR (Duration = "-0"))
  Exit := GN
 If (Duration)
   SetTimer, % "_Notify_Kill_" GN - GF + 1, % - Abs(Duration) * 1000
 Else
  SetTimer, % "_Notify_Flash_" GN - GF + 1, % BF

Return % GN

; when a notification is clicked:
_Notify_Action:
; Critical
 SetTimer, % "_Notify_Kill_" A_Gui - GF + 1, Off
 Gui, % A_Gui + GL - GF + 1 ":Destroy"
 Gui  %A_Gui%:+LastFound
 If SC
  DllCall("AnimateWindow","UInt",WinExist(),"Int",SC,"UInt", "0x00050001")
 Gui, %A_Gui%:Destroy
 If (ActionList)
  Loop,Parse,ActionList,|
   If ((Action := SubStr(A_LoopField,1,2)) = A_Gui)
   {
    Temp_Notify_Action:= SubStr(A_LoopField,4)
    StringReplace, ActionList, ActionList, % "|" A_Gui "=" Temp_Notify_Action, , All
    If IsLabel(_Notify_Action := Temp_Notify_Action)
     Gosub, %_Notify_Action%
    _Notify_Action =
    Break
   }
 StringReplace, NotifyList, NotifyList, % "|" GN, , All
 SetTimer, % "_Notify_Flash_" A_Gui - GF + 1, Off
 If (Exit = A_Gui)
  ExitApp
Return

; when a notification times out:
_Notify_Kill_1:
_Notify_Kill_2:
_Notify_Kill_3:
_Notify_Kill_4:
_Notify_Kill_5:
_Notify_Kill_6:
_Notify_Kill_7:
_Notify_Kill_8:
_Notify_Kill_9:
_Notify_Kill_10:
_Notify_Kill_11:
_Notify_Kill_12:
_Notify_Kill_13:
_Notify_Kill_14:
_Notify_Kill_15:
_Notify_Kill_16:
_Notify_Kill_17:
_Notify_Kill_18:
_Notify_Kill_19:
_Notify_Kill_20:
_Notify_Kill_21:
_Notify_Kill_22:
_Notify_Kill_23:
_Notify_Kill_24:
_Notify_Kill_25:
; Critical
 StringReplace, GK, A_ThisLabel, _Notify_Kill_
 SetTimer, _Notify_Flash_%GK%, Off
 GK += GF - 1
 Gui, % GK + GL - GF + 1 ":Destroy"
 Gui  %GK%:+LastFound
 If ST
  DllCall("AnimateWindow","UInt",WinExist(),"Int",ST,"UInt", "0x00050001")
 Gui, %GK%:Destroy
 StringReplace, NotifyList, NotifyList, % "|" GK
 If (Exit = GK)
  ExitApp
Return

; flashes a permanent notification:
_Notify_Flash_1:
_Notify_Flash_2:
_Notify_Flash_3:
_Notify_Flash_4:
_Notify_Flash_5:
_Notify_Flash_6:
_Notify_Flash_7:
_Notify_Flash_8:
_Notify_Flash_9:
_Notify_Flash_10:
_Notify_Flash_11:
_Notify_Flash_12:
_Notify_Flash_13:
_Notify_Flash_14:
_Notify_Flash_15:
_Notify_Flash_16:
_Notify_Flash_17:
_Notify_Flash_18:
_Notify_Flash_19:
_Notify_Flash_20:
_Notify_Flash_21:
_Notify_Flash_22:
_Notify_Flash_23:
_Notify_Flash_24:
_Notify_Flash_25:
 StringReplace, FlashGN, A_ThisLabel, _Notify_Flash_
 FlashGN += GF - 1
 FlashGN2 := FlashGN + GL - GF + 1
 If Flashed%FlashGN2% := !Flashed%FlashGN2%
  Gui, %FlashGN2%:Color, Silver
 Else
  Gui, %FlashGN2%:Color, % BC
Return

; wait for (or force) a notification to close:
_Notify_Wait_:
; Critical
 If (Image)
 {
  Gui %Image%:+LastFound
  If NotifyGuiID := WinExist()
  {
   WinWaitClose, , , % Abs(Duration)
   If (ErrorLevel && Duration < 1)
   {
    Gui, % Image + GL - GF + 1 ":Destroy"
    DllCall("AnimateWindow","UInt",NotifyGuiID,"Int",ST,"UInt","0x00050001")
    Gui, %Image%:Destroy
   }
  }
 }
 Else
 Loop, % GL-GF
 {
  Image := GL - (A_Index) ; + GF - 1)
  Gui %Image%:+LastFound
  If NotifyGuiID := WinExist()
  {
   ; WinWaitClose, , , % Abs(Duration)
   ; If (ErrorLevel && Duration < 1)
   ; {
    Gui, % Image + GL - GF + 1 ":Destroy"
    DllCall("AnimateWindow","UInt",NotifyGuiID,"Int",ST,"UInt","0x00050001")
    Gui, %Image%:Destroy
   ; }
  }
 }
Return
}

secsToStr(s)
{
    if (s >= 86400)
    {
        d := floor(s / 86400), s := mod(s, 86400)
        r := d " day"
        r .= (d <> 1) ? "s" : "", r .= (s > 0) ? ", " : ""
    }
    if (s >= 3600)
    {
        h := floor(s / 3600), s := mod(s, 3600)
        r .= h " hour"
        r .= (h <> 1) ? "s" : "", r .= (s > 0) ? ", " : ""
    }
    if (s >= 60)
    {
        m := floor(s / 60), s := mod(s, 60)
        r .= m " minute"
        r .= (m <> 1) ? "s" : "", r .= (s > 0) ? ", " : ""
    }
    r .= s " second", r .= (s <> 1) ? "s" : ""

    return, % r
}

;MsgBox, % secsToStr(1234567)

+^9::ExitApp
Esc::ExitApp
Rhys
Posts: 3
Joined: 04 Apr 2021, 23:11

Re: Countdown Timer

04 Apr 2021, 23:18

Blast from the past... Happy to see some old code still getting use :D
Bart1080
Posts: 1
Joined: 04 Jun 2021, 19:13

Re: Countdown Timer

16 Jul 2021, 20:14

Looks to be a handy timer by including the multiple options.

One thing I've been playing with is modifying the options....without success. Ive tried many different combo's and have hot a brick wall.
From what I can gather, the names of the options in line 30 isn't critical, they just appear on the options list and I've therefore simply added "F9" in front of the open file option for the purposes of selecting the correct 2nd option and testing?

eg: trying to get option 2 to press F9
In Line 122, I've added the following. Can anyone see why it would no work?
Note, the "or's" are examples of the different options I've tried, ....not the entire code :)

opa2:
Send, +{F9} or {+F9} or {+ down}{F9}

opb2:
return

Code: Select all

#NoEnv

rscrn := A_ScreenWidth-300

Gui , Timer:Show , w165 h140 X%rscrn% Y0, Timer
Gui , Timer: +hwndguiId +AlwaysOnTop +ToolWindow 
Gui , Timer:Font , s10 , Trebuchet MS                       
;   ===========================================================
Gui , Timer:add , Text , x0 y0 w40 center , Hrs
Gui , Timer:add , Text , x55 y0 w40 center , Min
Gui , Timer:add , Text , x110 y0 w40 center , Sec
;   ===========================================================
Gui , Timer:Add , Edit , x0 y16 w55 h20 center ve3
Gui , Timer:Add , UpDown , x0 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x55 y16 w55 h20 center ve2
Gui , Timer:Add , UpDown , x55 y16 w55 h20 -VScroll , 0
Gui , Timer:Add , Edit ,  x110 y16 w55 h20 center ve1,
Gui , Timer:Add , UpDown , x110 y16 w55 h20 -VScroll , 10
;   ===========================================================
Gui , Timer:Add , Button , gstart x0 y41 w80 h22 center vbStart, Re/Start
bStart_TT := "start countdown timer"
Gui , Timer:Add , Button , gresume x80 y41 w85 h22 center vbPause, P/Resume
bPause_TT := "pause or resume countdown timer"
;   ===========================================================
Gui , Timer:add, text , vTIdle x1 y105 w58 gopa7 , 00:00:00     
Tidle_TT := "PC idle time before auto countdown - 0 to disable"
Gui , Timer:add, text , vTStart x1 y120 w58 gSTTTT,
TStart_TT := "This is the time the timer last started."  
;   ===========================================================   
Gui, Timer:Add, DropDownList, vtimer_options Choose1 altsubmit x60 y113 w104 gset_option_func, No_option|F9Open File|System Beep|Message Box|Hybernate/Sleep|Shutdown|Start_After_Idle
timer_options_TT := "Select action to take."
;   ===========================================================
Gui , Timer:Font , s26 cBlue , Segoe UI
Gui , Timer:add , text , x0 y62 w169 h38 center vdispt gresume, C/D Timer
dispt_TT := "Time remaining on countdown"
;   ===========================================================
OnMessage(0x200, "MsMoveTTP")      
OnMessage(0x2A1, "HoverTTP") 
return

MsMoveTTP(wParam, lParam, msg, hwnd)
    {
    static TrackPos
     if (TrackPos = lParam)
     return
    TrackPos := lParam  
    tooltip
    cbSize:=(A_PtrSize+4)*2
    VarSetCapacity(TrkMEvnt, cbSize,0)
    NumPut(cbSize, TrkMEvnt, 0, "Uint")
    NumPut(3, TrkMEvnt, 4, "Uint")
    NumPut(hwnd, TrkMEvnt, 8, "Ptr")
    NumPut(800, TrkMEvnt, A_PtrSize+8, "Uint")
    DllCall("User32.dll\TrackMouseEvent", "uint", &TrkMEvnt)
    }
STTTT:
return
HoverTTP()
    {
    tooltip % %A_GuiControl%_TT
    }
return

start:
   Tog:=1
   Gui , Submit , NoHide
   Gui , Timer:Font , s26 cBlue , Segoe UI
   GuiControl , Timer:Font , dispt
    e3 := round(e3,3)
    e2 := round(e2,3)
    e1 := round(e1,3)
   secsLeft :=  e3*3600+e2*60+e1
   seconds := Format("{:02}" , floor(mod(secsLeft , 60)))       ;entry field
   minutes := Format("{:02}" , mod(floor(secsLeft/60) , 60))    
   hours  :=  floor(secsLeft/3600)                              
   
   hur := Format("{:02}" , floor(abs(secsleft)/3600))           ;display
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   
   GuiControl , Timer:text , dispt , %hur%:%min%:%sec% 
   FormatTime , TimeString, , HH:mm:ss               
   GuiControl , Timer:text , TStart , %TimeString%
   SetTimer , CDTimer , 1000
return

resume:
  if (hours+minutes+seconds < -1)
    goto start
    else SetTimer, CDTimer, % (Tog:=!Tog) ? "on":"off"
   GuiControl , , e3 , %hours%
   GuiControl , , e2 , %minutes%
   GuiControl , , e1 , %seconds%
   GuiControl , , dispt , %hur%:%min%:%sec%
return

CDTimer:
   secsLeft--
   hur := Format("{:02}" , floor(abs(secsleft)/3600))           ;display
   min := Format("{:02}" , floor(mod(abs(secsLeft/60),60)))
   sec := Format("{:02}" , floor(mod(abs(secsLeft), 60)))
   GuiControl , Timer:text , dispt, %hur%:%min%:%sec%
   secsLeft:=floor(secsleft)
   Ifequal, secsLeft,0
    {
    Gui , Timer:Font , s26 cRed , Segoe UI
    GuiControl , Timer:Font , dispt  
    goto  opb%timer_options%
    return
    }
   Else 
      Return
   
set_option_func:
   Gui , Submit , NoHide
   goto  opa%timer_options%
opa1:
opb1:
return

opa2:
Send, {+ down}{F9}

opb2:
return
   
opb3:
run %A_WinDir%\Media\alarm01.wav
opa3:
return

opb4:
   msgbox , 262144 , Timer, Time's Up !
opa4:
return

opb5:
   run, rundll32.exe powrprof.dll`,SetSuspendState Sleep
opa5:
return

opb6:
   run, shutdown.exe /s
opa6:
return

Check4Idle:
;   Gui , Submit , NoHide
;tooltip %A_TimeIdle%
if (IdleTCd < 1)
{
settimer Check4Idle, off
return
}
If (A_TimeIdle > IdleTCd*1000)
    {
    SetTimer Check4Idle, Off
    IdleTCd:=0
    goto start
    }
return

opa7: 
   Gui , Submit , NoHide
   inputbox, IdleTCd, Idle Time , Please enter minutes for PC to idle before auto countdown. 0 to disable, ,180 ,160
    idlhur := Format("{:02}" , floor(abs(IdleTCd)/60))
    idlmin := Format("{:02}" , floor(mod(abs(IdleTCd), 60)))
    idlsec := Format("{:02}" , floor(mod(abs(IdleTCd*60), 60)))
    IdleTCd := floor(IdleTCd*60)
    SetTimer , Check4Idle , 1000
    GuiControl , Timer:text , TIdle , %idlhur%:%idlmin%:%idlsec%
opb7:
return 

TimerGuiClose:
ExitApp
feeko
Posts: 51
Joined: 15 Apr 2022, 00:20

Re: Countdown Timer

04 Mar 2023, 15:16

Thanks for sharing that script @SpeedMaster!
User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Countdown Timer

04 Mar 2023, 16:24

Bart1080 wrote:trying to get option 2 to press F9
I see that this is your first post here, so let me start with...Welcome Aboard!

I haven't read any of the script that you posted, but to answer the question that you asked, this will press F9:

Code: Select all

Send {F9}
Related to what you posted, this will press F9 with the Shift key pressed:

Code: Select all

Send +{F9}
Also, note that SendInput is better than Send. As the doc says, "SendInput is generally the preferred method to send keystrokes and mouse clicks because of its superior speed and reliability." Also, rather than using SendInput each time, you can put SendMode Input near the top of your script, which changes to the SendInput method when coding Send (with known limitations...see the SendMode doc). Regards, Joe

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 196 guests