From 400bc2403da1c26b7d67a9786db0c3f94fbc4b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Thu, 20 Jul 2017 15:20:22 +0200 Subject: Add key repeat --- turtetris_master/usb_input.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'turtetris_master/usb_input.py') diff --git a/turtetris_master/usb_input.py b/turtetris_master/usb_input.py index dc01489..c452f7f 100644 --- a/turtetris_master/usb_input.py +++ b/turtetris_master/usb_input.py @@ -46,7 +46,7 @@ class Gamepad: self.state = {} for key in ['left', 'right', 'up', 'down', 'select', 'start']: - self.state[key] = False + self.state[key] = 0 def check(self): "Check the input state" @@ -62,7 +62,12 @@ class Gamepad: } changed = {} for key in ['left', 'right', 'up', 'down', 'select', 'start']: - changed[key] = new_state[key] and not self.state[key] - # TODO repeat - self.state = new_state + changed[key] = False + if new_state[key]: + if self.state[key] == 0 or self.state[key] > 14: + changed[key] = True + self.state[key] = 0 + self.state[key] += 1 + else: + self.state[key] = 0 return changed -- cgit v1.2.3