You're going to want to use a timer.
And I'm not sure why you're using those two #directives, they're not doing anything useful for that script.
But about using a timer:
SetTimer, TimerCallback, 180000
This creates a timer that fires the function (or label) TimerCallback
every 180,000 ms (180 sec).
Of course we're yet to define the function TimerCallback
, so lets do that now:
TimerCallback()
{
Tooltip, hi
}
And then to toggle the timer on/off on a hotkey:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
Explanation for toggle := !toggle
variable state toggling can be found from a previous answer of mine here.
Also includes an example for a sweet little 1liner timer toggling hotkey.
And here's the full example script:
^i::
toggle := !toggle ;a convenient way to toggle a variable in AHK, see below of explanation
if (toggle) ;if true
{
SetTimer, TimerCallback, 180000 ;turn on timer
;the function will only run for the first timer after
;those 180 secs, if you want it to run once immediately
;call the function here directly:
TimerCallback()
}
else
SetTimer, TimerCallback, Off ;turn off timer
return
TimerCallback()
{
Tooltip, hi
}