Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(enh) stop passing MSC scancodes and extra SYN events #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/keyszer/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -82,19 +83,32 @@ 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

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)
Expand Down
5 changes: 5 additions & 0 deletions src/keyszer/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down