Get the amount of time, in milliseconds, since the last time you have called this function.
You may have multiple timers using the ID parameter, defaults to 1.
You may reset all timers or a single one using the reset parameter.
Demo:
Code: Select all
; Demo:
j::ToolTip, % ggg.="1 :: " timeSinceLastCall(1) "`n"
k::ToolTip, % ggg.="2 :: " timeSinceLastCall(2) "`n"
l::ggg:="", timeSinceLastCall(0,1) ; reset everything
esc::ExitApp
Code: Select all
/*
timeSinceLastCall ( http://ahkscript.org/boards/viewtopic.php?f=6&t=537 )
Return the amount of time, in milliseconds, that has passed since you last called this function.
id = You may use different ID's to store different timesets. ID should be 1 and above (not 0 or negative) or a string.
reset = If reset is 1 and id is 0, all ID's are cleared. Otherwise if reset is 1, that specific id is cleared.
* NOTE:
The first call is usually blank.
example:
out:=timeSinceLastCall()
sleep, 500
out:=timeSinceLastCall()
output: 500
*/
timeSinceLastCall(id=1, reset=0)
{
static arr:=array()
if (reset=1)
{
((id=0) ? arr:=[] : (arr[id, 0]:=arr[id, 1]:="", arr[id, 2]:=0))
return
}
arr[id, 2]:=!arr[id, 2]
arr[id, arr[id, 2]]:=A_TickCount
return abs(arr[id,1]-arr[id,0])
}