-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiplePressListener.ahk
43 lines (36 loc) · 1.04 KB
/
MultiplePressListener.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class MultiplePressListener
{
__New(targetCount, onTriggeredFunc, timeout := 700)
{
this._targetCount := targetCount
this._count := 0
this._onTriggeredFunc := onTriggeredFunc
this._timeout := timeout
this._onTimeout := ObjBindMethod(this, "onTimeout")
}
Fire()
{
If (this._count > 0)
{
this._count += 1
return
}
this._count := 1
; SetTimer requires a plain variable reference
; Reference: https://autohotkey.com/docs/commands/SetTimer.htm#ExampleClass
timeoutFunc := this._onTimeout
SetTimer % timeoutFunc, % this._timeout
; todo: trigger when new count is equal to target count
; todo: handle interruption?
}
onTimeout()
{
timeoutFunc := this._onTimeout
SetTimer, % timeoutFunc, Off
If (this._count >= this._targetCount)
{
this._onTriggeredFunc.Call()
}
this._count := 0
}
}