- Notifications
You must be signed in to change notification settings - Fork0
[AHK v2] – Function that waits for a value to become true or a function to return true. Emulates built-in WinWait, KeyWait, etc. but supports any kind of check.
License
SALZKARTOFFEEEL/wait
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Waits for a value to become true or a function to return true.
Emulates built-inWinWait
,KeyWait
, etc. but supports any kind of check.
ret := wait(value, timeout :=0, interval :=100)
value
: The value continuously checkedor the function whose return value is continuously checked.value
is being called (used as a function),if it is considered callable.
timeout
–integer: Number of milliseconds to wait for at most.0
(the default) will cause it to wait indefinitely.interval
–integer: Number of milliseconds to wait before retrying.100
is the default.Specifying0
is valid and causes aSleep 0
.ret
: The return value.- If
timeout
was reached,ret
is an empty string. - Otherwise (if
value
became true),ret
isvalue
itself if it is not callable⁽¹⁾, or otherwisethe return value of the last call tovalue.call()
.
- If
value
is considered callable when either of these conditions is met:type(value) == "Func"
–value
is aFunc Object.type(value) == "BoundFunc"
–value
is aBoundFunc Object.value.hasMethod("Call")
–value
is aFunctor or any other object that implements aCall
method.
These conditions are tested for in the order specified above,with short-circuit evaluation.If either test throws an exception(though only the last one is expected to do so),
value
is considered not callable.wait
is able to throw an exception if the input arguments are invalid.timeout
andinterval
must both be apure Integer and be0
or greater.Any other exception is unintended and should be reported. Thank you!
; Example #1; This will wait 1 second before setting x to true.setTimer () => x :=true,-1000; This will consequently wait at least 1 second before continuing.wait x
; Example #2; This will wait until the Spacebar is pressed,; but will check for it much more frequently than KeyWait would.wait () =>getKeyState("Space"),,10
; Example #3; This is exactly equivalent to the previous example.waitfunc("getKeyState").bind("Space"),,10
; Example #4; This will wait for Joystick #1 to be plugged in; and display its name on the screen.msgbox"Joystick '" wait(() =>getKeyState("1JoyName"))"' has been plugged in!"