change countdown timer text color when reaches zero Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ravena1
Posts: 62
Joined: 06 Sep 2017, 15:13

change countdown timer text color when reaches zero

Post by ravena1 » 04 Jun 2023, 22:42

this script count to 5 everytime i press f3
how can i make countdown timer text color to red when reaches zero?



Code: Select all

;On-screen display (OSD)
CustomColor = 99AA55 ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s45 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cBlue, 00 ; 00 serve to auto-size the window.

WinSet, TransColor, %CustomColor% ; Make all pixels of this color transparent
Gui, Show, x800 y200 NoActivate ; NoActivate avoids deactivating the currently active window.
return


~f3:: ; hotkey will start or reset counting
counter:=0
SetTimer, UpdateOSD, -10 ; to update immediately
SetTimer, UpdateOSD, 1000
return


UpdateOSD:
counter++
time_display:=6-counter ; 6 and not 5 because counter starts with 1
if (time_display=0)
SetTimer, UpdateOSD, off ; stops the counter
GuiControl,, MyText, %time_display%
return


esc::exitapp

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: change countdown timer text color when reaches zero

Post by flyingDman » 04 Jun 2023, 23:13

Add:

Code: Select all

if !time_display
	{
	Gui, Font, cRed
	GuiControl, Font, MyText
	}
see https://www.autohotkey.com/docs/v1/lib/GuiControl.htm#Font
14.3 & 1.3.7

Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: change countdown timer text color when reaches zero  Topic is solved

Post by Rohwedder » 05 Jun 2023, 00:26

Hallo,
with it and a bit shorter:

Code: Select all

;On-screen display (OSD)
CustomColor = 99AA55 ; Can be any RGB color (it will be made transparent below).
Gui +LastFound +AlwaysOnTop -Caption +ToolWindow ; +ToolWindow avoids a taskbar button and an alt-tab menu item.
Gui, Color, %CustomColor%
Gui, Font, s45 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cBlue, 0%A_Space% ; Space serve to auto-size the window.
WinSet, TransColor, %CustomColor% ; Make all pixels of this color transparent
Gui, Show, x800 y200 NoActivate ; NoActivate avoids deactivating the currently active window.
return

~f3:: ; hotkey will start or reset counting
Gui, Font, cBlue
time_display := 6 ; 6 and not 5 because --time_display
SetTimer, UpdateOSD, 1000
UpdateOSD:
if !--time_display
{
	SetTimer, UpdateOSD, off ; stops the counter
	Gui, Font, cRed
}
GuiControl, Font, MyText
GuiControl,, MyText, %time_display%
return
esc::exitapp

Post Reply

Return to “Ask for Help (v1)”