Calling function with SetTimer

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
fabricio234
Posts: 122
Joined: 06 Mar 2020, 21:48

Calling function with SetTimer

15 May 2021, 02:57

I was searching for how to call a function using SetTimer and found this example:

https://www.autohotkey.com/boards/viewtopic.php?t=7340

Code: Select all

#Persistent

a := 12
fn := Func("z").Bind(a)
SetTimer, %fn%, -0

z(a)
{
    MsgBox, % a
}
How do you disable the timer when using a value > 0? As values < 0 is called only once :think:

-Edit-
Solved.

Using a obj:

Code: Select all

obj := {}
timer := Func("f").Bind(obj)
obj.Timer := timer
SetTimer, %timer%, -1

Sleep, 2000
return

f(arg, args*)
{
	timer := arg.Delete("Timer")
	SetTimer, %timer%, Delete

	MsgBox, %A_ThisFunc%
}
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Calling function with SetTimer

15 May 2021, 04:26

Hallo,
try:

Code: Select all

#Persistent

fn := Func("Beeps").Bind(A_TickCount + 1500)
SetTimer, %fn%, 200

Beeps(Until)
{
    SoundBeep, 4000, 20
	IF (A_TickCount > Until)
		SetTimer,, Off
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, mikeyww and 226 guests