-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_listener.py
202 lines (146 loc) · 5.21 KB
/
input_listener.py
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
from direct.task.Task import Task
class delta_caller:
def __init__(self,handle,trigger, index, value, cleanup_handle = None, cleanup_value = 0):
self.handle = handle
self.cleanup_handle = cleanup_handle
self.trigger = trigger
self.old_trigger = list(trigger)
self.index = index
self.trigger_activation = value
self.cleanup_activation = cleanup_value
def __call__(self,task):
if self.trigger[self.index] != self.old_trigger[self.index]:
self.old_trigger = list(self.trigger)
if self.trigger[self.index] == self.trigger_activation:
self.handle()
if self.cleanup_handle != None:
if self.trigger[self.index] == self.cleanup_activation:
self.cleanup_handle()
return Task.cont
class delta_caller_multikey:
def __init__(self,handle,trigger, indices, values, cleanup_handle = None, cleanup_values = 0):
self.handle = handle
self.cleanup_handle = cleanup_handle
self.trigger = trigger
self.old_trigger = list(trigger)
self.indices = indices
self.trigger_activations = values
self.cleanup_activations = cleanup_values
self.active = False
def __call__(self,task):
if self.trigger[self.indices[0]] != self.old_trigger[self.indices[0]]:
self.old_trigger = list(self.trigger)
should_call_handle = True
for i in range(len(self.indices)):
ind = self.indices[i]
if self.trigger[ind] != self.trigger_activations[i]:
should_call_handle = False
if should_call_handle:
self.handle()
self.active = True
if self.cleanup_handle != None and self.active:
should_call_cleanup = True
for i in range(len(self.indices)):
ind = self.indices[i]
if self.trigger[ind] != self.cleanup_activations[i]:
should_call_cleanup = False
if should_call_cleanup:
self.cleanup_handle()
return Task.cont
class hold_caller_multikey:
def __init__(self, trigger, indices, values, init_handle, loop_handle, cleanup_handle):
self.activated = False
self.trigger = trigger
self.indices = indices
self.trigger_activations = values
self.init_handle = init_handle
self.loop_handle = loop_handle
self.cleanup_handle = cleanup_handle
def __call__(self,task):
if self.activated == False and self.trigger[self.indices[0]] == self.trigger_activations[0]:
should_init = True
for i in range(len(self.indices)):
ind = self.indices[i]
if self.trigger[ind] != self.trigger_activations[i]:
should_init = False
if should_init:
if self.init_handle != None:
self.init_handle()
self.activated = True
return Task.cont
if self.activated == True and self.trigger[self.indices[0]] == self.trigger_activations[0]:
should_loop = True
for i in range(len(self.indices)):
ind = self.indices[i]
if self.trigger[ind] != self.trigger_activations[i]:
should_loop = False
if should_loop:
if self.loop_handle != None:
self.loop_handle()
return Task.cont
should_clean = False
if self.activated:
for i in range(len(self.indices)):
ind = self.indices[i]
if self.trigger[ind] != self.trigger_activations[i]:
should_clean = True
break
if should_clean:
if self.cleanup_handle != None:
self.cleanup_handle()
self.activated = False
return Task.cont
return Task.cont
class hold_caller:
def __init__(self, trigger, index, value, init_handle, loop_handle, cleanup_handle):
self.activated = False
self.trigger = trigger
self.index = index
self.trigger_activation = value
self.init_handle = init_handle
self.loop_handle = loop_handle
self.cleanup_handle = cleanup_handle
def __call__(self,task):
if self.activated == False and self.trigger[self.index] == self.trigger_activation:
if self.init_handle != None:
self.init_handle()
self.activated = True
if self.activated == True and self.trigger[self.index] == self.trigger_activation:
if self.loop_handle != None:
self.loop_handle()
if self.activated == True and self.trigger[self.index] != self.trigger_activation:
if self.cleanup_handle != None:
self.cleanup_handle()
self.activated = False
return Task.cont
class toggle_caller:
def __init__(self, trigger, index, value, init_handle, loop_handle, cleanup_handle):
self.activated = False
self.initialized = False
self.trigger = trigger
self.old_trigger = list(trigger)
self.index = index
self.trigger_activation = value
self.init_handle = init_handle
self.loop_handle = loop_handle
self.cleanup_handle = cleanup_handle
def __call__(self,task):
if self.activated == True and self.trigger[self.index] == 0:
if self.loop_handle != None:
self.loop_handle()
if self.trigger[self.index] != self.old_trigger[self.index]:
self.old_trigger = list(self.trigger)
if self.initialized == False and self.trigger[self.index] == self.trigger_activation:
if self.init_handle != None:
self.init_handle()
self.initialized = True
elif self.activated == False and self.initialized == True and self.trigger[self.index] != self.trigger_activation:
self.activated = True;
elif self.activated == True and self.trigger[self.index] != self.trigger_activation:
if self.cleanup_handle != None:
self.cleanup_handle()
self.activated = False
self.initialized = False
else:
pass
return Task.cont