diff --git a/src/keyszer/output.py b/src/keyszer/output.py index d87ed08..b0f9e93 100644 --- a/src/keyszer/output.py +++ b/src/keyszer/output.py @@ -56,6 +56,7 @@ def __init__(self): self._pressed_keys = set() self._suspended_mod_keys = [] self._suspend_depth = 0 + self._last_was_sync = False def __update_pressed_modifier_keys(self, key, action): if not Modifier.is_key_modifier(key): @@ -82,8 +83,13 @@ def diag(self): print(self._suspended_mod_keys) print("_suspend_depth", self._suspend_depth) + @staticmethod + def is_sync_event(event): + return event.code == 0 and event.type == 0 and event.value == 0 + def __send_sync(self): _uinput.syn() + self._last_was_sync = True def is_mod_pressed(self, key): return key in self._pressed_modifier_keys @@ -91,10 +97,18 @@ def is_mod_pressed(self, key): def is_pressed(self, key): return key in self._pressed_keys + def send_event(self, event): + # prevent just sending a bunch of syncs that sneak in + # from the input side, only send syncs if we have sent + # raw data from the input and it seems a sync may be + # needed + if (self._last_was_sync and Output.is_sync_event(event)): + return + _uinput.write_event(event) - # TODO: do we need this? I think not. - # self.__send_sync() + # debug(event.type, event.code, event.value, ctx="OO") + self._last_was_sync = Output.is_sync_event(event) def send_key_action(self, key, action): self.__update_pressed_modifier_keys(key, action) diff --git a/src/keyszer/transform.py b/src/keyszer/transform.py index bd0d319..99d0901 100644 --- a/src/keyszer/transform.py +++ b/src/keyszer/transform.py @@ -297,6 +297,11 @@ def find_keystate_or_new(inkey, action): # @benchit def on_event(event, device): + # do not pass thru any scancodes since we're very + # likely to be rewriting the keys anyways + if event.type == ecodes.EV_MSC: + return + # we do not attempt to transform non-key events # or any events with no device (startup key-presses) if event.type != ecodes.EV_KEY or device == None: