Add support for pressing two buttons on the same side
This commit is contained in:
parent
e4cca123c9
commit
848c9d2f74
@ -1,4 +1,7 @@
|
||||
|
||||
import time
|
||||
|
||||
|
||||
class InputManager:
|
||||
|
||||
currently_pressed_keys = []
|
||||
@ -7,6 +10,13 @@ class InputManager:
|
||||
right_paw_keys = []
|
||||
shifted_keys = {}
|
||||
|
||||
right_paw_repress_time = 0
|
||||
left_paw_repress_time = 0
|
||||
right_paw_repressed = False
|
||||
left_paw_repressed = False
|
||||
|
||||
repress_time = 0.05
|
||||
|
||||
def init(self, linux):
|
||||
if linux:
|
||||
import keylist_linux_fi as keys
|
||||
@ -21,12 +31,35 @@ class InputManager:
|
||||
for key in keys.left_paw_keys:
|
||||
self.left_paw_keys.append(key.lower())
|
||||
|
||||
def timer_update(self):
|
||||
curr_time = time.time()
|
||||
update = False
|
||||
if self.right_paw_repressed:
|
||||
delta = curr_time - self.right_paw_repress_time
|
||||
if delta > self.repress_time:
|
||||
self.right_paw_repressed = False
|
||||
update = True
|
||||
if self.left_paw_repressed:
|
||||
delta = curr_time - self.left_paw_repress_time
|
||||
if delta > self.repress_time:
|
||||
self.left_paw_repressed = False
|
||||
update = True
|
||||
if update:
|
||||
self.on_update(True)
|
||||
|
||||
def on_update(self, down):
|
||||
pass
|
||||
|
||||
def press_key(self, key):
|
||||
key = key.lower()
|
||||
if not key in self.currently_pressed_keys:
|
||||
if key in self.left_paw_keys and self.left_keys_pressed():
|
||||
self.left_paw_repressed = True
|
||||
self.left_paw_repress_time = time.time()
|
||||
if key in self.right_paw_keys and self.right_keys_pressed():
|
||||
self.right_paw_repressed = True
|
||||
self.right_paw_repress_time = time.time()
|
||||
|
||||
self.currently_pressed_keys.append(key)
|
||||
self.on_update(True)
|
||||
|
||||
@ -48,11 +81,11 @@ class InputManager:
|
||||
for key in self.currently_pressed_keys:
|
||||
if key in self.left_paw_keys:
|
||||
pressed = True
|
||||
return pressed
|
||||
return pressed and not self.left_paw_repressed
|
||||
|
||||
def right_keys_pressed(self):
|
||||
pressed = False
|
||||
for key in self.currently_pressed_keys:
|
||||
if key in self.right_paw_keys:
|
||||
pressed = True
|
||||
return pressed
|
||||
return pressed and not self.right_paw_repressed
|
||||
|
Loading…
Reference in New Issue
Block a user