summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Scheibenpflug <zorchenhimer@gmail.com>2016-10-29 15:39:51 (GMT)
committerNick Scheibenpflug <zorchenhimer@gmail.com>2016-10-29 15:39:51 (GMT)
commit7a373a0dae31ba38694abeb343e3e3fbd151967f (patch)
treef90a3e47145dd687f25c59935c7024b1ba70c5d7
parent39e72c981e3d5867431ef60f825a88f0cb2e55a4 (diff)
downloadcontroller-keyboard-7a373a0dae31ba38694abeb343e3e3fbd151967f.zip
controller-keyboard-7a373a0dae31ba38694abeb343e3e3fbd151967f.tar.gz
Unwrap RealHandler to JoyHandler
There isn't really any need to wrap this. It wasn't doing what it was designed to do and it adds a bunch of unneeded complexity.
-rw-r--r--lib/Environment.py2
-rw-r--r--lib/EventHandler.py604
-rw-r--r--lib/Keyboards.py4
3 files changed, 262 insertions, 348 deletions
diff --git a/lib/Environment.py b/lib/Environment.py
index 1b96129..e44650a 100644
--- a/lib/Environment.py
+++ b/lib/Environment.py
@@ -33,7 +33,7 @@ class EnvironmentController(object):
33 33
34 self.hud = HeadsUpDisplay() 34 self.hud = HeadsUpDisplay()
35 #self.controller = ControllerKeyboard(js, name='Controller Keyboard', hud=self.hud) 35 #self.controller = ControllerKeyboard(js, name='Controller Keyboard', hud=self.hud)
36 self.controller = ControllerKeyboard(jsnum, name='Controller Keyboard', hud=self.hud) 36 self.controller = ControllerKeyboard(jsnum, Name='Controller Keyboard', hud=self.hud)
37 self.keyboard_handler = KeyHandler(name="Keyboard") 37 self.keyboard_handler = KeyHandler(name="Keyboard")
38 self.TxtObject = Text('Derp|') 38 self.TxtObject = Text('Derp|')
39 39
diff --git a/lib/EventHandler.py b/lib/EventHandler.py
index 795ba3f..d1993a6 100644
--- a/lib/EventHandler.py
+++ b/lib/EventHandler.py
@@ -78,395 +78,309 @@ class JoyHandler(object):
78 """ 78 """
79 Handle all joystick input for the given context 79 Handle all joystick input for the given context
80 """ 80 """
81 class RealHandler(object): 81 class MrHat(object):
82 class MrHat(object): 82 """
83 """ 83 Update the values of the hat. Making this a class gives the
84 Update the values of the hat. Making this a class gives the 84 possibility of supporting more than one hat.
85 possibility of supporting more than one hat. 85 """
86 """ 86 def __init__(self, handler):
87 def __init__(self, handler): 87 self.__PosX = False
88 self.__PosX = False 88 self.__PosY = False
89 self.__PosY = False 89 self.__NegX = False
90 self.__NegX = False 90 self.__NegY = False
91 self.__NegY = False 91 self.__Handler = handler
92 self.__Handler = handler 92
93 93 def update(self, hat):
94 def update(self, hat): 94 ## Left/Right Keyup
95 ## Left/Right Keyup 95 if hat[0] == 0:
96 if hat[0] == 0: 96 ## Right
97 ## Right 97 if self.__PosX is not False:
98 if self.__PosX is not False: 98 self.__PosX = False
99 self.__PosX = False 99 self.__Handler.do_keyup('hatposx')
100 self.__Handler.do_keyup('hatposx') 100 ## Left
101 ## Left 101 if self.__NegX is not False:
102 if self.__NegX is not False: 102 self.__NegX = False
103 self.__NegX = False 103 self.__Handler.do_keyup('hatnegx')
104 self.__Handler.do_keyup('hatnegx') 104
105 105 ## Right Keydown
106 ## Right Keydown 106 if hat[0] == 1 and self.__PosX is not True:
107 if hat[0] == 1 and self.__PosX is not True: 107 if self.__NegX is True:
108 if self.__NegX is True: 108 self.__NegX = False
109 self.__NegX = False 109 self.__Handler.do_keyup('hatnegx')
110 self.__Handler.do_keyup('hatnegx') 110
111 111 self.__PosX = True
112 self.__PosX = True 112 self.__Handler.do_keydown('hatposx')
113 self.__Handler.do_keydown('hatposx') 113
114 114 ## Left Keydown
115 ## Left Keydown 115 if hat[0] == -1 and self.__NegX is not True:
116 if hat[0] == -1 and self.__NegX is not True: 116 if self.__PosX is True:
117 if self.__PosX is True: 117 self.__PosX = False
118 self.__PosX = False 118 self.__Handler.do_keyup('hatposx')
119 self.__Handler.do_keyup('hatposx') 119
120 120 self.__NegX = True
121 self.__NegX = True 121 self.__Handler.do_keydown('hatnegx')
122 self.__Handler.do_keydown('hatnegx') 122
123 123 ## Up/Down Keyup
124 ## Up/Down Keyup 124 if hat[1] == 0:
125 if hat[1] == 0: 125 ## Up
126 ## Up 126 if self.__PosY is not False:
127 if self.__PosY is not False: 127 self.__PosY = False
128 self.__PosY = False 128 self.__Handler.do_keyup('hatposy')
129 self.__Handler.do_keyup('hatposy') 129 ## Down
130 ## Down 130 if self.__NegY is not False:
131 if self.__NegY is not False: 131 self.__NegY = False
132 self.__NegY = False 132 self.__Handler.do_keyup('hatnegy')
133 self.__Handler.do_keyup('hatnegy') 133
134 134 ## Up Keydown
135 ## Up Keydown 135 if hat[1] == 1 and self.__PosY is not True:
136 if hat[1] == 1 and self.__PosY is not True: 136 if self.__NegY is True:
137 if self.__NegY is True: 137 self.__NegY = False
138 self.__NegY = False 138 self.__Handler.do_keyup('hatnegy')
139 self.__Handler.do_keyup('hatnegy') 139
140 140 self.__PosY = True
141 self.__PosY = True 141 self.__Handler.do_keydown('hatposy')
142 self.__Handler.do_keydown('hatposy') 142
143 143 ## Down Keydown
144 ## Down Keydown 144 if hat[1] == -1 and self.__NegY is not True:
145 if hat[1] == -1 and self.__NegY is not True: 145 if self.__PosY is True:
146 if self.__PosY is True: 146 self.__PosY = False
147 self.__PosY = False 147 self.__Handler.do_keyup('hatposy')
148 self.__Handler.do_keyup('hatposy') 148
149 149 self.__NegY = True
150 self.__NegY = True 150 self.__Handler.do_keydown('hatnegy')
151 self.__Handler.do_keydown('hatnegy')
152
153 def __repr__(self):
154 return self.__str__()
155
156 def __str__(self):
157 return "<MrHat(PosX={}, NegX={}, PosY={}, NegY={})>".format(
158 self.__PosX,
159 self.__NegX,
160 self.__PosY,
161 self.__NegY)
162
163 class MrAxis(object):
164 """ Manage axis values """
165 def __init__(self, joyid, axisid, handler):
166 # +/- for each axis
167 self.__Value = 0.0
168 self.__Deadzone = 0.2
169 self.__AxisID = axisid
170 self.__Handler = handler
171 self.__Joystick = pygame.joystick.Joystick(joyid)
172
173 # For menu navigation and hat emulation
174 self.__Pos = False
175 self.__Neg = False
176
177 def update(self):
178 self.__Value = self.__Joystick.get_axis(self.__AxisID)
179 if self.__Value > (0 + self.__Deadzone):
180 if self.__Pos is False:
181 self.__Handler.do_keydown("a" + str(self.__AxisID) + "pos")
182 if self.__Neg is True:
183 self.__Handler.do_keyup("a" + str(self.__AxisID) + "neg")
184
185 self.__Pos = True
186 self.__Neg = False
187 elif self.__Value < (0 - self.__Deadzone):
188 if self.__Pos is True:
189 self.__Handler.do_keyup("a" + str(self.__AxisID) + "pos")
190 if self.__Neg is False:
191 self.__Handler.do_keydown("a" + str(self.__AxisID) + "neg")
192
193 self.__Pos = False
194 self.__Neg = True
195 else:
196 if self.__Pos is True:
197 self.__Handler.do_keyup("a" + str(self.__AxisID) + "pos")
198 if self.__Neg is True:
199 self.__Handler.do_keyup("a" + str(self.__AxisID) + "neg")
200 self.__Pos = False
201 self.__Neg = False
202
203 def get_hat_value(self):
204 # heh...
205 return 1 if self.__Pos else -1 if self.__Neg else 0
206
207 def get_value(self):
208 return self.__Value
209
210 def __repr__(self):
211 return self.__str__()
212
213 def __str__(self):
214 return "<MrAxis(Value={}, Deadzone={}, Pos={}, Neg={}, AxisID={})>".format(
215 self.__Value,
216 self.__Deadzone,
217 self.__Pos,
218 self.__Neg,
219 self.__AxisID)
220
221 class MrStick(object):
222 """ Manage stick values. """
223 def __init__(self, joy_id, axisX_id, axisY_id, handler):
224 self.__X = JoyHandler.RealHandler.MrAxis(joy_id, axisX_id, handler)
225 self.__Y = JoyHandler.RealHandler.MrAxis(joy_id, axisY_id, handler)
226 self.__Handler = handler
227
228 def get_hat_value():
229 return [self.__X.get_hat_value(), self.__Y.get_hat_value()]
230
231 def get_value(self):
232 return (self.__X.get_value(), self.__Y.get_value())
233
234 def get_intensity(self):
235 norm_x = self.__X.get_value() * 100 + 0.00001
236 norm_y = self.__Y.get_value() * 100 + 0.00001
237 return math.floor(math.sqrt(math.pow(norm_x, 2) + math.pow(norm_y, 2)))
238
239 def get_sector(self):
240 angle = 0
241 norm_x = self.__X.get_value() + 0.00001
242 norm_y = self.__Y.get_value() + 0.00001
243
244 intensity = self.get_intensity()
245
246 if norm_x != 0:
247 angle = math.atan(norm_y/norm_x) * (180 / math.pi)
248 if norm_x > 0:
249 angle += 180
250 elif norm_y > 0:
251 angle += 360
252
253 if intensity > 25:
254 if angle < 22.5:
255 return 'w'
256 elif angle < 67.5:
257 return 'nw'
258 elif angle < 112.5:
259 return 'n'
260 elif angle < 157.5:
261 return 'ne'
262 elif angle < 202.5:
263 return 'e'
264 elif angle < 247.5:
265 return 'se'
266 elif angle < 292.5:
267 return 's'
268 elif angle < 337.5:
269 return 'sw'
270 return 'w'
271 return 'x'
272
273 def update(self):
274 self.__X.update()
275 self.__Y.update()
276
277 def __repr__(self):
278 return self.__str__()
279
280 def __str__(self):
281 return "<MrStick(X={}Y={}>".format(self.__X, self.__Y)
282
283
284 """ RealHandler start """
285 def __init__(self, rID, name=None, jID=0):
286 self.ButtonHandler = KeyHandler(str(name) + " [auto]")
287
288 self.hat = JoyHandler.RealHandler.MrHat(self.ButtonHandler)
289 self.axes = []
290 self.joystick = pygame.joystick.Joystick(jID)
291 self.joystick.init()
292 self.Name = name
293 self.randID = rID
294
295 i = 0
296 self.num_axes = pygame.joystick.Joystick(jID).get_numaxes()
297 print('Joystick id {} number of axes: {}'.format(jID, self.num_axes))
298 self.LeftStick = JoyHandler.RealHandler.MrStick(jID, 0, 1, self.ButtonHandler)
299 self.RightStick = JoyHandler.RealHandler.MrStick(jID, 4, 3, self.ButtonHandler)
300 self.TriggerAxis = JoyHandler.RealHandler.MrAxis(jID, 2, self.ButtonHandler)
301 self.TriggerStick = JoyHandler.RealHandler.MrStick(jID, 2, 5, self.ButtonHandler)
302 #while i < self.num_axes:
303 # if (i + 2) < num_axes:
304 # self.axes.append(JoyHandler.RealHandler.MrStick(jID, i, i+1, self.ButtonHandler))
305 # i += 2
306 # else:
307 # self.axes.append(JoyHandler.RealHandler.MrAxis(jID, i, self.ButtonHandler))
308 # i += 1
309
310 def update(self):
311 ## I can't find a controller with more than one hat that isn't the
312 ## Virtual Boy controller. We don't care about any more than one in
313 ## that case.
314 if self.joystick.get_numhats() > 0:
315 self.hat.update(self.joystick.get_hat(0))
316
317 ## Axes on the other hand...
318 for a in self.axes:
319 a.update()
320
321 self.LeftStick.update()
322 self.RightStick.update()
323 #self.TriggerStick.update()
324 self.TriggerAxis.update()
325
326 def get_hat_value(self, hat):
327 return self.hat
328
329 def get_stick_value(self, stick='left'):
330 if stick == 'left':
331 return self.LeftStick.get_value()
332 elif stick == 'trigger':
333 return self.TriggerStick.get_value()
334 else:
335 return self.RightStick.get_value()
336
337 def get_sector(self, stick):
338 if stick == 'right':
339 return self.RightStick.get_sector()
340 return self.LeftStick.get_sector()
341 151
342 def get_intensity(self, stick): 152 def __repr__(self):
343 if stick == 'right': 153 return self.__str__()
344 return self.RightStick.get_intensity()
345 return self.LeftStick.get_intensity()
346
347 def get_trigger_axis_value(self):
348 return self.TriggerAxis.get_value()
349 154
350 ## Because why write shit twice? 155 def __str__(self):
351 def dump_bindings(self): 156 return "<MrHat(PosX={}, NegX={}, PosY={}, NegY={})>".format(
352 self.ButtonHandler.dump_bindings() 157 self.__PosX,
158 self.__NegX,
159 self.__PosY,
160 self.__NegY)
161
162 class MrAxis(object):
163 """ Manage axis values """
164 def __init__(self, joyid, axisid, handler):
165 # +/- for each axis
166 self.__Value = 0.0
167 self.__Deadzone = 0.2
168 self.__AxisID = axisid
169 self.__Handler = handler
170 self.__Joystick = pygame.joystick.Joystick(joyid)
171
172 # For menu navigation and hat emulation
173 self.__Pos = False
174 self.__Neg = False
353 175
354 def do_joydown(self, button, joy=0): 176 def update(self):
355 if joy == self.joystick.get_id(): 177 self.__Value = self.__Joystick.get_axis(self.__AxisID)
356 self.ButtonHandler.do_keydown(button) 178 if self.__Value > (0 + self.__Deadzone):
179 if self.__Pos is False:
180 self.__Handler.do_keydown("a" + str(self.__AxisID) + "pos")
181 if self.__Neg is True:
182 self.__Handler.do_keyup("a" + str(self.__AxisID) + "neg")
183
184 self.__Pos = True
185 self.__Neg = False
186 elif self.__Value < (0 - self.__Deadzone):
187 if self.__Pos is True:
188 self.__Handler.do_keyup("a" + str(self.__AxisID) + "pos")
189 if self.__Neg is False:
190 self.__Handler.do_keydown("a" + str(self.__AxisID) + "neg")
357 191
358 def do_joyup(self, button, joy=0): 192 self.__Pos = False
359 if joy == self.joystick.get_id(): 193 self.__Neg = True
360 self.ButtonHandler.do_keyup(button) 194 else:
195 if self.__Pos is True:
196 self.__Handler.do_keyup("a" + str(self.__AxisID) + "pos")
197 if self.__Neg is True:
198 self.__Handler.do_keyup("a" + str(self.__AxisID) + "neg")
199 self.__Pos = False
200 self.__Neg = False
361 201
362 def add_joydown_handle(self, button, callback, args=None, joy=0): 202 def get_hat_value(self):
363 if joy == self.joystick.get_id(): 203 # heh...
364 self.ButtonHandler.add_keydown_handle(button, callback, args) 204 return 1 if self.__Pos else -1 if self.__Neg else 0
365 205
366 def add_joyup_handle(self, button, callback, args=None, joy=0): 206 def get_value(self):
367 if joy == self.joystick.get_id(): 207 return self.__Value
368 self.ButtonHandler.add_keyup_handle(button, callback, args)
369 208
370 def add_joyhold_handle(self, button, callback, joy=0): 209 def __repr__(self):
371 if joy == self.joystick.get_id(): 210 return self.__str__()
372 self.ButtonHandler.add_keyhold_handle(button, callback)
373 211
374 def clear_all(self): 212 def __str__(self):
375 self.ButtonHandler.clear_all() 213 return "<MrAxis(Value={}, Deadzone={}, Pos={}, Neg={}, AxisID={})>".format(
214 self.__Value,
215 self.__Deadzone,
216 self.__Pos,
217 self.__Neg,
218 self.__AxisID)
219
220 class MrStick(object):
221 """ Manage stick values. """
222 def __init__(self, joy_id, axisX_id, axisY_id, handler):
223 self.__X = JoyHandler.MrAxis(joy_id, axisX_id, handler)
224 self.__Y = JoyHandler.MrAxis(joy_id, axisY_id, handler)
225 self.__Handler = handler
226
227 def get_hat_value():
228 return [self.__X.get_hat_value(), self.__Y.get_hat_value()]
229
230 def get_value(self):
231 return (self.__X.get_value(), self.__Y.get_value())
232
233 def get_intensity(self):
234 norm_x = self.__X.get_value() * 100 + 0.00001
235 norm_y = self.__Y.get_value() * 100 + 0.00001
236 return math.floor(math.sqrt(math.pow(norm_x, 2) + math.pow(norm_y, 2)))
237
238 def get_sector(self):
239 angle = 0
240 norm_x = self.__X.get_value() + 0.00001
241 norm_y = self.__Y.get_value() + 0.00001
242
243 intensity = self.get_intensity()
244
245 if norm_x != 0:
246 angle = math.atan(norm_y/norm_x) * (180 / math.pi)
247 if norm_x > 0:
248 angle += 180
249 elif norm_y > 0:
250 angle += 360
251
252 if intensity > 25:
253 if angle < 22.5:
254 return 'w'
255 elif angle < 67.5:
256 return 'nw'
257 elif angle < 112.5:
258 return 'n'
259 elif angle < 157.5:
260 return 'ne'
261 elif angle < 202.5:
262 return 'e'
263 elif angle < 247.5:
264 return 'se'
265 elif angle < 292.5:
266 return 's'
267 elif angle < 337.5:
268 return 'sw'
269 return 'w'
270 return 'x'
376 271
377 def copy(self): 272 def update(self):
378 return copy.copy(self) 273 self.__X.update()
274 self.__Y.update()
379 275
380 def __repr__(self): 276 def __repr__(self):
381 return self.__str__() 277 return self.__str__()
382 278
383 def __str__(self): 279 def __str__(self):
384 return "<RealHandler(Name={}, axes={}, hat={})>".format( 280 return "<MrStick(X={}Y={}>".format(self.__X, self.__Y)
385 self.Name,
386 self.axes,
387 self.hat)
388 281
389 """
390 Wrapper below. If we find a joystick, use JoyHandler.RealHandler().
391 Otherwise quietly ignore all joystick actions.
392 """
393 def __init__(self, jID, name=None):
394 pygame.joystick.init()
395 self.real_handle = None
396 rand = random.Random()
397 self.randID = rand.randint(0, 100000)
398 282
399 if pygame.joystick.get_count() > 0: 283 """ RealHandler start """
400 self.real_handle = JoyHandler.RealHandler(self.randID, name=name, jID=jID) 284 def __init__(self, name=None, jID=0):
401 else: 285 self.ButtonHandler = KeyHandler(str(name) + " [auto]")
402 if name is not None: 286
403 self.Name = name + " [DUMMY]" 287 self.hat = JoyHandler.MrHat(self.ButtonHandler)
404 else: 288 self.axes = []
405 self.Name = "[DUMMY]" 289 self.joystick = pygame.joystick.Joystick(jID)
406 self.ButtonHandler = KeyHandler(str(self.Name) + " [auto]") 290 self.joystick.init()
291 self.Name = name
292
293 i = 0
294 self.num_axes = pygame.joystick.Joystick(jID).get_numaxes()
295 print('Joystick id {} number of axes: {}'.format(jID, self.num_axes))
296 self.LeftStick = JoyHandler.MrStick(jID, 0, 1, self.ButtonHandler)
297 self.RightStick = JoyHandler.MrStick(jID, 4, 3, self.ButtonHandler)
298 self.TriggerAxis = JoyHandler.MrAxis(jID, 2, self.ButtonHandler)
299 self.TriggerStick = JoyHandler.MrStick(jID, 2, 5, self.ButtonHandler)
300 #while i < self.num_axes:
301 # if (i + 2) < num_axes:
302 # self.axes.append(JoyHandler.MrStick(jID, i, i+1, self.ButtonHandler))
303 # i += 2
304 # else:
305 # self.axes.append(JoyHandler.MrAxis(jID, i, self.ButtonHandler))
306 # i += 1
407 307
408 def update(self): 308 def update(self):
409 if self.real_handle is not None: 309 ## I can't find a controller with more than one hat that isn't the
410 return self.real_handle.update() 310 ## Virtual Boy controller. We don't care about any more than one in
311 ## that case.
312 if self.joystick.get_numhats() > 0:
313 self.hat.update(self.joystick.get_hat(0))
411 314
412 def get_hat_value(self, hat): 315 ## Axes on the other hand...
413 if self.real_handle is not None: 316 for a in self.axes:
414 return self.real_handle.get_hat_value(hat) 317 a.update()
415 return (0, 0)
416 318
417 def get_trigger_axis_value(self): 319 self.LeftStick.update()
418 if self.real_handle is not None: 320 self.RightStick.update()
419 return self.real_handle.get_trigger_axis_value() 321 #self.TriggerStick.update()
322 self.TriggerAxis.update()
420 323
421 #def get_axis_value(self, axis): 324 def get_hat_value(self, hat):
422 # if self.real_handle is not None: 325 return self.hat
423 # return self.real_handle.get_axis_value(axis)
424 # return 0
425 326
426 def get_stick_value(self, stick='left'): 327 def get_stick_value(self, stick='left'):
427 if self.real_handle is not None: 328 if stick == 'left':
428 return self.real_handle.get_stick_value(stick) 329 return self.LeftStick.get_value()
330 elif stick == 'trigger':
331 return self.TriggerStick.get_value()
332 else:
333 return self.RightStick.get_value()
429 334
430 def get_sector(self, stick='left'): 335 def get_sector(self, stick='left'):
431 if self.real_handle is not None: 336 if stick == 'right':
432 return self.real_handle.get_sector(stick) 337 return self.RightStick.get_sector()
338 return self.LeftStick.get_sector()
433 339
434 def get_intensity(self, stick='left'): 340 def get_intensity(self, stick='left'):
435 if self.real_handle is not None: 341 if stick == 'right':
436 return self.real_handle.get_intensity(stick) 342 return self.RightStick.get_intensity()
343 return self.LeftStick.get_intensity()
344
345 def get_trigger_axis_value(self):
346 return self.TriggerAxis.get_value()
347
348 ## Because why write shit twice?
349 def dump_bindings(self):
350 self.ButtonHandler.dump_bindings()
437 351
438 def do_joydown(self, button, joy=0): 352 def do_joydown(self, button, joy=0):
439 if self.real_handle is not None: 353 if joy == self.joystick.get_id():
440 self.real_handle.do_joydown(button, joy) 354 self.ButtonHandler.do_keydown(button)
441 355
442 def do_joyup(self, button, joy=0): 356 def do_joyup(self, button, joy=0):
443 if self.real_handle is not None: 357 if joy == self.joystick.get_id():
444 self.real_handle.do_joyup(button, joy) 358 self.ButtonHandler.do_keyup(button)
445 359
446 def add_joydown_handle(self, button, callback, args=None, joy=0): 360 def add_joydown_handle(self, button, callback, args=None, joy=0):
447 if self.real_handle is not None: 361 if joy == self.joystick.get_id():
448 self.real_handle.add_joydown_handle(button, callback, args,) 362 self.ButtonHandler.add_keydown_handle(button, callback, args)
449 363
450 def add_joyup_handle(self, button, callback, args=None, joy=0): 364 def add_joyup_handle(self, button, callback, args=None, joy=0):
451 if self.real_handle is not None: 365 if joy == self.joystick.get_id():
452 self.real_handle.add_joyup_handle(button, callback, args, joy) 366 self.ButtonHandler.add_keyup_handle(button, callback, args)
453 367
454 def add_joyhold_handle(self, button, callback, joy=0): 368 def add_joyhold_handle(self, button, callback, joy=0):
455 if self.real_handle is not None: 369 if joy == self.joystick.get_id():
456 self.real_handle.add_joyhold_handle(button, callback, joy) 370 self.ButtonHandler.add_keyhold_handle(button, callback)
457 371
458 def clear_all(self): 372 def clear_all(self):
459 if self.real_handle is not None: 373 self.ButtonHandler.clear_all()
460 self.real_handle.clear_all()
461 374
462 def copy(self): 375 def copy(self):
463 if self.real_handle is not None: 376 return copy.copy(self)
464 return copy.copy(self)
465 return self
466 377
467 def __repr__(self): 378 def __repr__(self):
468 return self.__str__() 379 return self.__str__()
469 380
470 def __str__(self): 381 def __str__(self):
471 return "<JoyHandler(real_handle={}>".format(self.real_handle) 382 return "<RealHandler(Name={}, axes={}, hat={})>".format(
383 self.Name,
384 self.axes,
385 self.hat)
472 386
diff --git a/lib/Keyboards.py b/lib/Keyboards.py
index 4cabd2c..c371df4 100644
--- a/lib/Keyboards.py
+++ b/lib/Keyboards.py
@@ -19,9 +19,9 @@ class TraditionalKeyboard(Keyboard):
19 pass 19 pass
20 20
21class ControllerKeyboard(Keyboard): 21class ControllerKeyboard(Keyboard):
22 def __init__(self, js, name='[j-noname]', hud=None): 22 def __init__(self, js, Name='[j-noname]', hud=None):
23 self.js = js 23 self.js = js
24 self.handler = JoyHandler(js) 24 self.handler = JoyHandler(Name, js)
25 self.hud = hud 25 self.hud = hud
26 26
27 self.line_color = (200, 10, 10) 27 self.line_color = (200, 10, 10)