Adding Milliseconds to a timer, and improving the responsiveness of the timer itself

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dnus
Posts: 1
Joined: 29 Mar 2024, 15:27

Adding Milliseconds to a timer, and improving the responsiveness of the timer itself

29 Mar 2024, 15:31

Hi all,

I have the following code that opens an app and posts something at a specific time. It's completely dorky, it's just a silly competition my friends and I are having to see who can get it to post first at exactly noon each day.

Two primary issues. First of all, if I use "120000" for the following Timestring, the code itself takes a few seconds to run and it ends up fully executed around 12:00:03, which is too late. Currently I'm trying to circumvent this by just building in the three extra seconds, which you can see in the code below. Is there a way to get this to execute.... faster?

Tangentially, I'd also love to be able to add milliseconds to the Timestring check so I can make it even more accurate.

Any suggestions on this? I'm kinda a newb with it. Thanks so much.

Code: Select all

#Persistent
ToolTip, WAITING TO POST!
SetTimer, Timer, 1 ; check every 1 milliseconds
Return

Timer:
FormatTime, TimeString,, HHmmss
if (TimeString = "115957")  ; put whatever time in 24 hour format
{
	RunWait C:\Users\nusde\AppData\Local\Discord\app-1.0.9037\Discord.exe
	send, https://twitter.com/GatorsDaily/status/1618979677376315393
	send, {Enter}
	ExitApp

}
else
{
	ToolTip, WAITING FOR FLAT FUCK FRIDAY!
}
Return
[Mod edit: Moved topic from AHK v2 help since this is v1 code.]
User avatar
mikeyww
Posts: 26991
Joined: 09 Sep 2014, 18:38

Re: Adding Milliseconds to a timer, and improving the responsiveness of the timer itself

29 Mar 2024, 15:42

Welcome to this AutoHotkey forum!

Run the program in advance. At the appointed time, just activate the window before sending your text.

You might be able to simplify your approach by using the Windows Task Scheduler. This can run your script at the appointed time, though I'm not sure what timer period the Task Scheduler uses. I suppose it might use a frequency of one second. I would still have your target program running in advance.

You might want to use SetBatchLines in your script.

My hunch would be that your real timer frequency is 15-16 ms rather than 1 ms, but you can verify that through testing.

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

Code: Select all

#Requires AutoHotkey v1.1.33.11
#Persistent
SetBatchLines -1
Process Priority,, H
Run notepad
SetTimer Timer, 50
Timer:
If SubStr(A_Now, 9) = "170000" {
 WinActivate ahk_exe notepad.exe
 SendInput 123`n
 MsgBox 64, Time, % A_Now
 ExitApp
}
Return

Code: Select all

#Requires AutoHotkey v2.0
ProcessSetPriority 'H'
Run 'notepad'
SetTimer timer, 50

timer() {
 If SubStr(A_Now, 9) = '190300' {
  WinActivate 'ahk_exe notepad.exe'
  Send '123`n'
  MsgBox A_Now, 'Time', 'Iconi'
  ExitApp
 }
}

Return to “Ask for Help (v1)”

Who is online

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