Currently, you can specify a negative timing value to SetTimer() to request a single execution, and a positive value to request repeated executions. It would be really handy to have a method to request that the first call of a timer to be executed at a different/specific time.
Timers are a great way to separate execution into a different thread in order to avoid locking up hot-key threads for repeating actions. I often initialize my repeating timers with a small negative value to begin, then have the timer callback function update that time to a specific positive rate after the first call.
Something I think would be really useful would be an optional first_call duration parameter to SetTimer(), which relates only to the first execution of the timer callback after SetTimer() is called. I find myself needing to adjust the first execution of timers pretty often. So from my own limited experience with AHK, it seems like this would be a useful feature.
Separate Timer First-Execution Duration
Re: Separate Timer First-Execution Duration
I don't think I'll implement this because:
It can be done in v1, but I prefer not to write v1 code.
- It is extremely trivial to achieve the desired effect already.
- I don't recall having a need for it myself.
Code: Select all
#Requires AutoHotkey v2.0-a
SetTimerFirst(() => ToolTip("Tick @ " A_Sec), 2000, 1000)
SetTimerFirst(fn, first, other) => SetTimer(() => (SetTimer(fn, other), fn()), -Abs(first))
Who is online
Users browsing this forum: No registered users and 44 guests