-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_timer.ahk
122 lines (116 loc) · 2.7 KB
/
class_timer.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
; timer := timer.new("Function Name", interval, priority)
class timer {
error[] {
get {
return this._error
}
}
isRunning[]{
get {
return this._isRunning
}
}
count[]{
get {
return this._count
}
}
name[]{
get{
return this._func
}
}
func[]{
get {
return this._func
}
}
interval[]{
get {
return this._interval
}
set {
if (this._isInteger(value)){
this._interval := value
if (this._isRunning)
this.Restart()
this._error := false
} else{
this._Exception("'" value "' is not an integer`nInterval is unchanged")
}
}
}
priority[]{
get {
return this._priority
}
set {
if (this._isInteger(value)){
this._priority := value
if (this._isRunning)
this.Restart()
this._error := false
} else{
this._Exception("'" value "' is not an integer`nPriority is unchanged")
}
}
}
__New(func,i:=250,p:=0) {
this._count := 0
this._timer := ObjBindMethod(this, "_Tick")
this._isRunning := false
this._error := false
if (this._isInteger(i))
this._interval:=i
else
this._Exception("'" value "' is not an integer`nInterval is unchanged")
if (this._isInteger(p))
this._priority:=p
else
this._Exception("'" value "' is not an integer`nPriority is unchanged")
if (isfunc(func)){
this._func:=func
this._name:=func
}
else {
this._error := true
this._func := null
this._Exception("That function doesn't exist`nSpecifically: " func)
}
}
Start() {
if (!this._error){
SetTimer this._timer, this._interval, this._priority
this._isRunning := true
}
}
Stop() {
this._count := 0
SetTimer this._timer, 0
this._isRunning:=false
}
Restart(){
this.Stop()
this.Start()
}
_Exception(m){
this.Stop()
this._error := true
Throw(m)
}
_isInteger(i){
if (i is "Integer")
return True
else
return False
}
_Tick() {
if (this._isRunning && this.func != null){
this._count++
f:= this._func
try {
%f%()
}
}
}
}