boppreh/keyboard

I added a keyboard.is_pressed resetter

PogoDigitalism opened this issue · 1 comments

"
def reset_is_pressed(hotkey):
if _is_number(hotkey):
# Shortcut.
with _pressed_events_lock:
if hotkey in _pressed_events:
_pressed_events.pop(hotkey)
return True
else:
raise ValueError("Hotkey is not registered.")

steps = parse_hotkey(hotkey)
if len(steps) > 1:
    raise ValueError("Impossible to check if multi-step hotkeys are pressed (`a+b` is ok, `a, b` isn't).")

with _pressed_events_lock:
    pressed_scan_codes = set(_pressed_events)
for scan_codes in steps[0]:

    scan_code_to_del = next((scan_code for scan_code in scan_codes if scan_code in pressed_scan_codes), None)
    if not scan_code_to_del:
        raise ValueError("Hotkey is not registered.")
    elif scan_code_to_del in scan_codes:
        _pressed_events.pop(scan_code_to_del)
        return True
return True

"
Located in init.py
Using it to reset the is_pressed(hotkey) on command instead of making it a one-time only condition that can be ran.

cant seem to format the code properly in this issue