Adjusting a countdown timer script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Adjusting a countdown timer script

Post by acnl » 06 Jan 2021, 05:32

I was able to change the code so that the initial text is green, but I would still like assistance with having the red text and red border turn off and on every 2 seconds, once the countdown reaches 0. If anyone could help, it would be much appreciated! Here is the current code.

Code: Select all

#SingleInstance force

CustomColor = 000000
Ed := 100 ;Edge width
Transparency := 20
Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
Gui, Font, s32 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cGreen, MACRO+SUPPLY
WinSet, TransColor, %CustomColor%
WinSet, ExStyle, ^0x20 ;WS_EX_CLICKTHROUGH
Gui, Show, x650 y500 NoActivate
W := A_ScreenWidth ,H := A_ScreenHeight, WE := W - Ed, WH := H - Ed
Gui, New, +LastFound -DPIScale +AlwaysOnTop -Caption +ToolWindow +HwndEdge
Gui, Color, 0xFF0000
WinSet, Transparent,% Transparency
WinSet, ExStyle, ^0x20
WinSet, Region, 0-0 %W%-0 %W%-%H% 0-%H% 0-0 %Ed%-%Ed% %WE%-%Ed% %WE%-%WH% %Ed%-%WH% %Ed%-%Ed%
return

!e::
counter:=0
Gui, Font, cGreen
GuiControl, Font, MyText
Gosub, UpdateOSD
SetTimer, UpdateOSD, 1000
return

UpdateOSD:
counter++
time_display:=30-counter
if (time_display=0)
{
	SetTimer, UpdateOSD, off
	time_display = MACRO+SUPPLY
	Gui, Font, cRed
	GuiControl, Font, MyText
	Gui,%Edge%: Show, x0 y0 w%W% h%H% NoActivate
}
Else
	WinHide, ahk_id %Edge%
GuiControl,, MyText, %time_display%
return

WheelUp::
reload
return
Last edited by acnl on 08 Jan 2021, 22:54, edited 1 time in total.

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 07 Jan 2021, 01:23

Still looking for help~ thank you!

BoBo
Posts: 4333
Joined: 13 May 2014, 17:15

Re: Adjusting a countdown timer script

Post by BoBo » 07 Jan 2021, 02:34

Limiting your initial support request to a single supporter isn’t the smartest move. JMHO. :shh:

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 07 Jan 2021, 03:52

@BoBo

haha, I am sorry. It's just that he made the script for me and he's usually online. I think he's taking a break. If you can help adjust this script, I would be very appreciative. Thank you~

BoBo
Posts: 4333
Joined: 13 May 2014, 17:15

Re: Adjusting a countdown timer script

Post by BoBo » 07 Jan 2021, 04:41

1. When the script is first loaded, can the text that is shown be green?
Just add a color-parameter to the initial :arrow: Gui, Font, ... setting.
Flashing AKA 'changing its color' can be accomplished using a :arrow: SetTimer-routine that is getting disabled once the counter is reset. And yes, that way you can adjust its frequency as well.

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 07 Jan 2021, 05:11

I think I can adjust the first part but I really don't have any idea how I can make the red text and red border flash once the countdown reaches zero. it shouldn't change color, just flash on and off every 1 second until I press !e to reset the countdown. please help me~

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 07 Jan 2021, 22:30

I was able to change the code so that the initial text is green, but I would still like assistance with having the red text and red border turn off and on every 2 seconds, once the countdown reaches 0. If anyone could help, it would be much appreciated! Here is the current code.

Code: Select all

#SingleInstance force

CustomColor = 000000
Ed := 100 ;Edge width
Transparency := 20
Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
Gui, Font, s32 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cGreen, MACRO+SUPPLY
WinSet, TransColor, %CustomColor%
WinSet, ExStyle, ^0x20 ;WS_EX_CLICKTHROUGH
Gui, Show, x650 y500 NoActivate
W := A_ScreenWidth ,H := A_ScreenHeight, WE := W - Ed, WH := H - Ed
Gui, New, +LastFound -DPIScale +AlwaysOnTop -Caption +ToolWindow +HwndEdge
Gui, Color, 0xFF0000
WinSet, Transparent,% Transparency
WinSet, ExStyle, ^0x20
WinSet, Region, 0-0 %W%-0 %W%-%H% 0-%H% 0-0 %Ed%-%Ed% %WE%-%Ed% %WE%-%WH% %Ed%-%WH% %Ed%-%Ed%
return

!e::
counter:=0
Gui, Font, cGreen
GuiControl, Font, MyText
Gosub, UpdateOSD
SetTimer, UpdateOSD, 1000
return

UpdateOSD:
counter++
time_display:=30-counter
if (time_display=0)
{
	SetTimer, UpdateOSD, off
	time_display = MACRO+SUPPLY
	Gui, Font, cRed
	GuiControl, Font, MyText
	Gui,%Edge%: Show, x0 y0 w%W% h%H% NoActivate
}
Else
	WinHide, ahk_id %Edge%
GuiControl,, MyText, %time_display%
return

WheelUp::
reload
return

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 08 Jan 2021, 05:25

bump. Looking for help~

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 08 Jan 2021, 22:53

@Rohwedder

Could you take a look at this when you have time? Much appreciated!

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 09 Jan 2021, 22:11

Still looking for help T_T can anyone help?

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: Adjusting a countdown timer script

Post by Epialis » 10 Jan 2021, 10:24

acnl wrote:
09 Jan 2021, 22:11
Still looking for help T_T can anyone help?
Might not be much help, but what about something like this? ... maybe set transparency to 100 to see better?

Code: Select all

	loop 5 {	
	WinHide, ahk_id %Edge%
	WinShow, ahk_id %Edge%
	GuiControl, show, mytext
	sleep 2000
	GuiControl, show, mytext
	GuiControl, hide, mytext
	}

Just thinking outside the box lol... blessings

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 10 Jan 2021, 20:34

hey thanks for the help! Yeah this script is complicated and making it flash is not easy cuz the red text is actually 0 transparency and the red border is transparent. how can I make it so that they both turn on and off at the same every 2 seconds until the timer is reset? still hoping for a complete solution.

User avatar
Epialis
Posts: 722
Joined: 02 Aug 2020, 22:44

Re: Adjusting a countdown timer script  Topic is solved

Post by Epialis » 10 Jan 2021, 21:57

acnl wrote:
10 Jan 2021, 20:34
how can I make it so that they both turn on and off at the same every 2 seconds until the timer is reset? still hoping for a complete solution.

Countdowns to 0 and then flashes every two seconds until you mousewheel up or hit hotkey again to restart.

Is this better?

Code: Select all

#SingleInstance force

CustomColor = 000000
Ed := 100 ;Edge width
Transparency := 120
Gui, +LastFound +AlwaysOnTop -Caption +ToolWindow
Gui, Color, %CustomColor%
Gui, Font, s32 ; Set a large font size (32-point).
Gui, Add, Text, vMyText cGreen, MACRO+SUPPLY
WinSet, TransColor, %CustomColor%
WinSet, ExStyle, ^0x20 ;WS_EX_CLICKTHROUGH
Gui, Show, x650 y500 NoActivate
W := A_ScreenWidth ,H := A_ScreenHeight, WE := W - Ed, WH := H - Ed
Gui, New, +LastFound -DPIScale +AlwaysOnTop -Caption +ToolWindow +HwndEdge
Gui, Color, 0xFF0000
WinSet, Transparent,% Transparency
WinSet, ExStyle, ^0x20
WinSet, Region, 0-0 %W%-0 %W%-%H% 0-%H% 0-0 %Ed%-%Ed% %WE%-%Ed% %WE%-%WH% %Ed%-%WH% %Ed%-%Ed%
return

!e::
counter:=0
Gui, Font, cGreen
GuiControl, Font, MyText
Gosub, UpdateOSD
SetTimer, UpdateOSD, 1000
return

UpdateOSD:
counter++
time_display:=3-counter
if (time_display=0)
{
	Guicontrol,, Mytext, 1
	SetTimer, UpdateOSD, off
	time_display = MACRO+SUPPLY
	Gui, Font, cRed
	
	GuiControl, Font, MyText
	Gui,%Edge%: Show, x0 y0 w%W% h%H% NoActivate
		loop {
	Guicontrol,, Mytext, 0
	WinHide, ahk_id %Edge%
	WinShow, ahk_id %Edge%
	GuiControl, show, mytext
	sleep 2000
	GuiControl, show, mytext
	GuiControl, hide, mytext
	}
}
Else
	WinHide, ahk_id %Edge%
GuiControl,, MyText, %time_display%
return

WheelUp::
reload
return

Esc::ExitApp

User avatar
Hellbent
Posts: 1180
Joined: 23 Sep 2017, 13:34

Re: Adjusting a countdown timer script

Post by Hellbent » 10 Jan 2021, 22:08

Something like this?

Code: Select all

; Topic: https://www.autohotkey.com/boards/viewtopic.php?f=76&t=85366
;***************************************************************************************************
#Include <My Altered Gdip Lib>  ;<------       Replace with your copy of GDIP
;***************************************************************************************************
#Include <LayeredWindow Class>  ;Topic: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=72588&p=368552
;***************************************************************************************************
#SingleInstance, Force
SetBatchLines, -1
WINDOW_WIDTH := A_ScreenWidth, WINDOW_HEIGHT := A_ScreenHeight, TEXT_X := 680, TEXT_Y := 530
TEXT_VALUE := "MACRO+SUPPLY", BORDER_COLOR := "0x00FF0000", TEXT_COLOR := "0xFF008000", FONT_SIZE := 42
Window1 := New LayeredWindow(x := 0 , y := 0 , w := WINDOW_WIDTH , h := WINDOW_HEIGHT , window := 1 , title := " " , smoothing := 2 , options := "+AlwaysOnTop -DPIScale +ToolWindow +E0x20" , autoShow := 1 , GdipStart := 1 )
Window1.Draw( HB_BITMAP_MAKER(WINDOW_WIDTH, WINDOW_HEIGHT, TEXT_X , TEXT_Y, TEXT_VALUE, BORDER_COLOR, TEXT_COLOR, FONT_SIZE) , Positions := {X:0,Y:0,W:WINDOW_WIDTH,H:WINDOW_HEIGHT} , update := 1 , disposeBitmap := 1  , PaintBackground := 0)
return

*ESC::
	Window1.DeleteWindow( TurnOffGdip := 1 )
	ExitApp

!e::
	counter := 31
	Gosub, UpdateOSD
	SetTimer, UpdateOSD, 1000
	return

UpdateOSD:
	if(--Counter <= 0){
		TEXT_VALUE := "MACRO+SUPPLY"
		(Tog := !Tog) ? (BORDER_COLOR := "0x55FF0000", TEXT_COLOR := "0xFFFF0000") : (BORDER_COLOR := "0x55008000", TEXT_COLOR := "0xFF008000")
	}else{
		TEXT_VALUE := Counter
		BORDER_COLOR := "0x00FF0000"
		TEXT_COLOR := "0xFF008000"
	}
	Window1.ClearWindow()
	Window1.Draw( HB_BITMAP_MAKER(WINDOW_WIDTH, WINDOW_HEIGHT, TEXT_X , TEXT_Y, TEXT_VALUE, BORDER_COLOR, TEXT_COLOR, FONT_SIZE) , Positions := {X:0,Y:0,W:WINDOW_WIDTH,H:WINDOW_HEIGHT} , update := 1 , disposeBitmap := 1  , PaintBackground := 0)
	return

WheelUp::
	Window1.DeleteWindow( TurnOffGdip := 1 )
	reload
	return

HB_BITMAP_MAKER(w, h, tx, ty, Text, BorderColor, TextColor, FontSize){
	;Bitmap Created Using: HB Bitmap Maker
	pBitmap := Gdip_CreateBitmap( w , h ), G := Gdip_GraphicsFromImage( pBitmap ), Gdip_SetSmoothingMode( G , 2 )
	Pen := Gdip_CreatePen( BorderColor , 50 ), Gdip_DrawRectangle( G , Pen , 25 , 25 , w-50 , h-50 ), Gdip_DeletePen( Pen )
	Brush := Gdip_BrushCreateSolid( TextColor ), Gdip_TextToGraphics( G , Text , "s" FontSize " Left Bold c" Brush " x" tx " y" ty , "Arial" , w-tx , 70 ), Gdip_DeleteBrush( Brush )
	Gdip_DeleteGraphics( G )
	return pBitmap
}
I'll do a non-Gdi+ version shortly. This just makes it look a lot nicer!

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 11 Jan 2021, 01:29

@Hellbent thank you for the help! I was about to give up thinking my request was too difficult. this is very interesting. I am new to AHK so I don't know what GDIP is. I will try to research and make it work on my pc. yes, if you could also make a non-gdi+ version, that would also be great! thank you!

User avatar
Hellbent
Posts: 1180
Joined: 23 Sep 2017, 13:34

Re: Adjusting a countdown timer script

Post by Hellbent » 11 Jan 2021, 01:58

acnl wrote:
11 Jan 2021, 01:29
@Hellbent thank you for the help! I was about to give up thinking my request was too difficult. this is very interesting. I am new to AHK so I don't know what GDIP is. I will try to research and make it work on my pc. yes, if you could also make a non-gdi+ version, that would also be great! thank you!
You can get the GDIP Library here: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6517

User avatar
Hellbent
Posts: 1180
Joined: 23 Sep 2017, 13:34

Re: Adjusting a countdown timer script

Post by Hellbent » 11 Jan 2021, 02:00

Alternatively you can also get it here included in a function list clip tool.

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=61911

acnl
Posts: 49
Joined: 25 Nov 2017, 09:04

Re: Adjusting a countdown timer script

Post by acnl » 11 Jan 2021, 02:13

@Hellbent

Thank you! for the non gdi+ version, is it possible to make this script? I feel like I am so close to the solution. Would appreciate your solution if you have time.

User avatar
Hellbent
Posts: 1180
Joined: 23 Sep 2017, 13:34

Re: Adjusting a countdown timer script

Post by Hellbent » 11 Jan 2021, 02:41

acnl wrote:
11 Jan 2021, 02:13
@Hellbent

Thank you! for the non gdi+ version, is it possible to make this script? I feel like I am so close to the solution. Would appreciate your solution if you have time.
Epialis had posted something at the same time as I posted my solution so I didn't bother making a non-GDIP solution.
Does his code not work?

Post Reply

Return to “Ask For Help”