Test key_is_down

Related #2273
This commit is contained in:
MattHag 2024-10-13 11:55:00 +02:00 committed by Peter F. Patel-Schneider
parent a36973916c
commit badb76953d
2 changed files with 9 additions and 3 deletions

View File

@ -1478,15 +1478,15 @@ built_in_rules = Rule(
) )
def key_is_down(key): def key_is_down(key: NamedInt) -> bool:
"""Checks if given key is pressed or not."""
if key == CONTROL.MR: if key == CONTROL.MR:
return mr_key_down return mr_key_down
elif CONTROL.M1 <= key <= CONTROL.M8: elif CONTROL.M1 <= key <= CONTROL.M8:
return bool(m_keys_down & (0x01 << (key - CONTROL.M1))) return bool(m_keys_down & (0x01 << (key - CONTROL.M1)))
elif CONTROL.G1 <= key <= CONTROL.G32: elif CONTROL.G1 <= key <= CONTROL.G32:
return bool(g_keys_down & (0x01 << (key - CONTROL.G1))) return bool(g_keys_down & (0x01 << (key - CONTROL.G1)))
else: return key in keys_down
return key in keys_down
def evaluate_rules(feature, notification: HIDPPNotification, device): def evaluate_rules(feature, notification: HIDPPNotification, device):

View File

@ -82,3 +82,9 @@ def test_diversion_rule():
assert isinstance(key, diversion.Key) assert isinstance(key, diversion.Key)
key = component.components[1] key = component.components[1]
assert isinstance(key, diversion.KeyPress) assert isinstance(key, diversion.KeyPress)
def test_key_is_down():
result = diversion.key_is_down(key=diversion.CONTROL.G2)
assert result is False