Need help adding time to this AHK Countdown timer Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
amace
Posts: 1
Joined: 22 Jan 2024, 12:56

Need help adding time to this AHK Countdown timer

Post by amace » 22 Jan 2024, 13:02

Please help. I have this countdown timer GUI working as I'd like, but I want to add a portion that increases the time by a set amount (ex. 15 minutes) when a particular key is pressed (ex. F4). I'm relatively new to AHK and would appreciate any help provided!

Code: Select all


#Persistent 
CoordMode, Mouse, Screen 
MouseGetPos, MX, MY 
Gui 6: +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui 6: Color, FFFFFA
Gui 6: Font, s30, Calibri
Gui 6: Add, Text, x0 y0 w200 vdisp cwhite,
Gui 6: Show, x%MX% y%MY% w200
WinSet TransColor, FFFFFA,
Gui 6:show,NoActivate,Display
CountDown = 000100  ; 6 digits = HHmmSS 
C = %A_TickCount% 
SetTimer ShowTime 

ShowTime: 
   T = 20000101%CountDown% 
   T += (C-A_TickCount)/1000,Seconds 
   FormatTime FormdT, %T%, H : mm : ss 
   guicontrol 6:text,disp,%FormdT%
   IfEqual FormdT, 0 : 00 : 00, SetTimer ShowTime, Off 
   IfEqual FormdT, 0 : 00 : 00, Run C:\Desktop\AHK Lock.ahk
	IfEqual FormdT, 0 : 00 : 00, ExitApp
Return


F2:: Reload
F3:: ExitApp

[Mod edit: Moved topic from AHK v2 help since this is v1 code.]

sofista
Posts: 654
Joined: 24 Feb 2020, 13:59
Location: Buenos Aires

Re: Need help adding time to this AHK Countdown timer

Post by sofista » 22 Jan 2024, 19:30

Hi: You are unnecessarily mixing up legacy and expression syntaxes, also using some deprecated commands. Try to use expression syntax as much as possible, as follows:

Code: Select all

#Persistent 
CoordMode, Mouse, Screen
MouseGetPos, MX, MY
Gui 6: +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui 6: Color, FFFFFA
Gui 6: Font, s30, Calibri
Gui 6: Add, Text, x0 y0 w200 vdisp cwhite
Gui 6: Show, x%MX% y%MY% w200
WinSet TransColor, FFFFFA
Gui 6: Show, NoActivate, Display
CountDown := "000100"  ; 6 digits = HHmmSS
C := A_TickCount
SetTimer ShowTime, 1000

ShowTime:
	T := "20000101" CountDown
	if (A_ThisHotkey = "F4")
		T += "2000010100" newT
	T += (C-A_TickCount)/1000, Seconds
	FormatTime FormdT, % T, H : mm : ss
	guicontrol 6:text, disp, % FormdT
	if (FormdT = "0 : 00 : 00") {
		SetTimer ShowTime, Off
		Run C:\Desktop\AHK Lock.ahk
		ExitApp
	}
Return

F2:: Reload
F3:: ExitApp
F4:: newT := 1500    ; 15 minutes
Now, if you want a more flexible approach to add some minutes, replace the F4 line with this other:

Code: Select all

F4:: Input, newT, L4 T5, {Enter}    ; type in "1500" (without the quotes) for 15 minutes
See the Input command for an explanation.

User avatar
mikeyww
Posts: 27192
Joined: 09 Sep 2014, 18:38

Re: Need help adding time to this AHK Countdown timer  Topic is solved

Post by mikeyww » 22 Jan 2024, 19:37

Mine is below.

Code: Select all

F4::
C += 60000 * MINS := 15
Gosub ShowTime
Return

Post Reply

Return to “Ask for Help (v1)”