From cf0a71913ee61b4ea0d9c6a92c80c1640745c599 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sun, 13 Feb 2022 19:51:11 -0500 Subject: [PATCH] rules: track M keys and MR keys for use in rules --- lib/logitech_receiver/diversion.py | 21 ++++++++++++++++++++- lib/logitech_receiver/special_keys.py | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index bacf2143..4905cd33 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -811,13 +811,15 @@ if x11: keys_down = [] g_keys_down = [0, 0, 0, 0] +m_keys_down = 0 +mr_key_down = False # process a notification def process_notification(device, status, notification, feature): if not x11: return - global keys_down, g_keys_down, key_down, key_up + global keys_down, g_keys_down, m_keys_down, mr_key_down, key_down, key_up key_down, key_up = None, None # need to keep track of keys that are down to find a new key down if feature == _F.REPROG_CONTROLS_V4 and notification.address == 0x00: @@ -841,6 +843,23 @@ def process_notification(device, status, notification, feature): if old_byte & (0x01 << (i - 1)) and not new_byte & (0x01 << (i - 1)): key_up = _CONTROL['G' + str(i + 8 * byte_idx)] g_keys_down = new_g_keys_down + # and also M keys down + elif feature == _F.MKEYS and notification.address == 0x00: + new_m_keys_down = _unpack('!1B', notification.data[:1]) + for i in range(1, 9): + if new_m_keys_down & (0x01 << (i - 1)) and not m_keys_down & (0x01 << (i - 1)): + key_down = _CONTROL['M' + str(i + 8 * byte_idx)] + if m_keys_down & (0x01 << (i - 1)) and not new_m_keys_down & (0x01 << (i - 1)): + key_up = _CONTROL['M' + str(i + 8 * byte_idx)] + m_keys_down = new_m_keys_down + # and also MR key + elif feature == _F.MR and notification.address == 0x00: + new_mr_key_down = _unpack('!1B', notification.data[:1]) + if not mr_key_down and new_mr_key_down: + key_down = _CONTROL['MR'] + if mr_key_down and not new_mr_key_down: + key_up = _CONTROL['MR'] + mr_key_down = new_mr_key_down rules.evaluate(feature, notification, device, status, True) diff --git a/lib/logitech_receiver/special_keys.py b/lib/logitech_receiver/special_keys.py index 10ff7ace..496dfd0f 100644 --- a/lib/logitech_receiver/special_keys.py +++ b/lib/logitech_receiver/special_keys.py @@ -276,6 +276,9 @@ CONTROL = _NamedInts( for i in range(1, 33): # add in G keys - these are not really Logitech Controls CONTROL[0x1000 + i] = 'G' + str(i) +for i in range(1, 9): # add in M keys - these are not really Logitech Controls + CONTROL[0x1100 + i] = 'M' + str(i) +CONTROL[0x1200] = 'MR' # add in MR key - this is not really a Logitech Control CONTROL._fallback = lambda x: 'unknown:%04X' % x