Simple countdown/up to a .txt file

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nano9
Posts: 5
Joined: 16 Jun 2021, 15:26

Simple countdown/up to a .txt file

16 Jun 2021, 15:34

Hello,

I am looking for a simple script which records countdown or countup to a txt file, can you help in creating of such a script?
The timer (hours:minutes:seconds) I would like to edit directly in a script file, no need of any windows like in a script below.

And at the end of countdown I would like to add the following script:

Code: Select all

Title := "Please Confirm?", Sec := 30

SetTimer, Countdown, 1000

MsgBox, 64, %Title%, Will launch in %Sec% seconds, %Sec%

Return

Countdown:

 ControlSetText, Static2, % "Will launch in " (Sec:=Sec-1) " seconds"

               , %Title% ahk_class #32770

Return
For writing to a .txt file I'm using another script for other purpose:

Code: Select all

~^z::    ;
FileDelete, ctrlz.txt
++cnt    ;
FileAppend, Counter: %cnt%`n, ctrlz.txt
Return

Thank you.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Simple countdown/up to a .txt file

17 Jun 2021, 02:16

Hallo,
An example of coutdown:

Code: Select all

q::
FileDelete, CountDown.txt
Start = 012345 ;1 hour 23 minutes 45 seconds
Clock = 20000101%Start%
SetTimer, Clock, 1000
Return
Clock:
Clock += -1, Seconds
FormatTime, FClock,% Clock, HH:mm:ss
ToolTip,% FClock
FileAppend, %FClock%`n, CountDown.txt
IF FClock = 00:00:00
    SetTimer, Clock, Off  
Return
Nano9
Posts: 5
Joined: 16 Jun 2021, 15:26

Re: Simple countdown/up to a .txt file

17 Jun 2021, 03:30

Rohwedder wrote:
17 Jun 2021, 02:16
Hallo,
An example of coutdown:

Code: Select all

q::
FileDelete, CountDown.txt
Start = 012345 ;1 hour 23 minutes 45 seconds
Clock = 20000101%Start%
SetTimer, Clock, 1000
Return
Clock:
Clock += -1, Seconds
FormatTime, FClock,% Clock, HH:mm:ss
ToolTip,% FClock
FileAppend, %FClock%`n, CountDown.txt
IF FClock = 00:00:00
    SetTimer, Clock, Off  
Return
Hey! It's working fine!
Timer is following courser (can it be fixed? a txt file with timer is only needed) and as I intend to send this timer to OBS, txt file have to contain only one string, so can the script delete and create the file each second, so the file will always have only one number in hh:m:s? As with ctrl+z script above?

Thank you
Nano9
Posts: 5
Joined: 16 Jun 2021, 15:26

Re: Simple countdown/up to a .txt file

17 Jun 2021, 05:45

This is what following my mouse cursor
 
Image
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Simple countdown/up to a .txt file

17 Jun 2021, 07:56

Then,

Code: Select all

q::
Start = 012345 ;1 hour 23 minutes 45 seconds
Clock = 20000101%Start%
SetTimer, Clock, 1000
Return
Clock:
FileDelete, CountDown.txt
Clock += -1, Seconds
FormatTime, FClock,% Clock, HH:mm:ss
ToolTip,% FClock, 100, 100
FileAppend, %FClock%, CountDown.txt
IF FClock = 00:00:00
    SetTimer, Clock, Off  
Return
What followed your cursor was just a tooltip. I have now set this to the window coordinates 100, 100.
If you don't need it, just delete it.
Nano9
Posts: 5
Joined: 16 Jun 2021, 15:26

Re: Simple countdown/up to a .txt file

17 Jun 2021, 12:13

Rohwedder wrote:
17 Jun 2021, 07:56
Then,

Code: Select all

q::
Start = 012345 ;1 hour 23 minutes 45 seconds
Clock = 20000101%Start%
SetTimer, Clock, 1000
Return
Clock:
FileDelete, CountDown.txt
Clock += -1, Seconds
FormatTime, FClock,% Clock, HH:mm:ss
ToolTip,% FClock, 100, 100
FileAppend, %FClock%, CountDown.txt
IF FClock = 00:00:00
    SetTimer, Clock, Off  
Return
What followed your cursor was just a tooltip. I have now set this to the window coordinates 100, 100.
If you don't need it, just delete it.
Works fine now!
Another thing, how can I launch the script, execute the timer without pressing any button?
And also I have tried to change timer value to 0 hour 00 minutes 05 seconds, but it did not affect the time you set originally, don't know why.
Rohwedder
Posts: 7616
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Simple countdown/up to a .txt file

17 Jun 2021, 13:35

Then:

Code: Select all

Goto, q ;execute the timer without pressing any button
q::
Start = 000005 ; 00 hours 00 minutes 05 seconds
Clock = 20000101%Start%
SetTimer, Clock, 1000
Return
Clock:
FileDelete, CountDown.txt
Clock += -1, Seconds
FormatTime, FClock,% Clock, HH:mm:ss
ToolTip,% FClock, 100, 100
FileAppend, %FClock%, CountDown.txt
IF FClock = 00:00:00
    SetTimer, Clock, Off  
Return
Nano9
Posts: 5
Joined: 16 Jun 2021, 15:26

Re: Simple countdown/up to a .txt file

18 Jun 2021, 05:44

I don't get how do you change the time
you set 00005 for 5 sec, I tired 3600 for 1 hour, but it did not work, it showed only 35 minutes
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Simple countdown/up to a .txt file

18 Jun 2021, 06:04

Bc a timestamp is used instead of milliseconds you‘ve to follow the 'HHmmss' pattern. So a minute would look like 000100 and an hour 010000. HTH
User avatar
emrekarahan0001
Posts: 25
Joined: 18 Jan 2021, 14:19

Re: Simple countdown/up to a .txt file

05 Jul 2021, 07:40

Maybe this?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

Gui, +ToolWindow -Theme +AlwaysOnTop
Gui, Color, 0d0e14, 33333a
Gui, Font, s13 cffffff
Gui, Add, Edit, x10 y10 w50 h25 vMinute, 
Gui, Add, Edit, x+15 y10 w50 h25 vSecond, 
Gui, Add, Button, x+15 y10 w50 h25 gOK, OK
Gui, Show, xCenter yCenter w200 h100, Convert MilliSeconds to mm:ss
Return

OK:
GuiControlGet, Minute
GuiControlGet, Second
vMin := Minute
vSec := Second

vTotal := vMin*60000+vSec*1000
Gui, Font, s13 cSilver
Gui, Add, Text, x10 y50, Milliseconds = 
Gui, Font, s13 cefff3d
Gui, Add, Text, x+5 y50, % vTotal

vSec := % vTotal //1000 ;330 ;% vTotal
Gui, Font, s13 cSilver
Gui, Add, Text, x10 y70, Minute:Second = 
Gui, Font, s13 cefff3d
Gui, Add, Text, x+5 y70, % Format("{:02}:{:02}", Mod(vSec, 3600)//60, Mod(vSec, 60))
Return

GuiEscape:
GuiClose:
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 107 guests