fix pystack exhaust during resume_process_key.
Instead of handling resumed key events in a deep stack, buffer them until the next main loop iteration. New resume events that may be emitted during handling of old resumes are prepended to that buffer, i.e. take precedence over events that happen deeper into the buffer/event stack. Logical replay order is thus preserved.
This commit is contained in:
@@ -191,10 +191,11 @@ class Combos(Module):
|
||||
)
|
||||
else:
|
||||
# There's no matching combo: send and reset key buffer
|
||||
self.send_key_buffer(keyboard)
|
||||
self._key_buffer = []
|
||||
if int_coord is not None:
|
||||
key = keyboard._find_key_in_map(int_coord)
|
||||
if self._key_buffer:
|
||||
self._key_buffer.append((int_coord, key, True))
|
||||
self.send_key_buffer(keyboard)
|
||||
self._key_buffer = []
|
||||
key = None
|
||||
|
||||
return key
|
||||
|
||||
@@ -251,8 +252,10 @@ class Combos(Module):
|
||||
elif len(combo._remaining) == len(combo.match) - 1:
|
||||
self.reset_combo(keyboard, combo)
|
||||
if not self.count_matching():
|
||||
self._key_buffer.append((int_coord, key, False))
|
||||
self.send_key_buffer(keyboard)
|
||||
self._key_buffer = []
|
||||
key = None
|
||||
|
||||
# Anything between first and last key released.
|
||||
else:
|
||||
@@ -295,17 +298,7 @@ class Combos(Module):
|
||||
|
||||
def send_key_buffer(self, keyboard):
|
||||
for (int_coord, key, is_pressed) in self._key_buffer:
|
||||
new_key = None
|
||||
if not is_pressed:
|
||||
try:
|
||||
new_key = keyboard._coordkeys_pressed[int_coord]
|
||||
except KeyError:
|
||||
new_key = None
|
||||
if new_key is None:
|
||||
new_key = keyboard._find_key_in_map(int_coord)
|
||||
|
||||
keyboard.resume_process_key(self, new_key, is_pressed, int_coord)
|
||||
keyboard._send_hid()
|
||||
keyboard.resume_process_key(self, key, is_pressed, int_coord)
|
||||
|
||||
def activate(self, keyboard, combo):
|
||||
combo.result.on_press(keyboard)
|
||||
|
Reference in New Issue
Block a user