boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.79k stars 432 forks source link

I added a keyboard.is_pressed resetter #609

Open PogoDigitalism opened 1 year ago

PogoDigitalism commented 1 year ago

" 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.

PogoDigitalism commented 1 year ago

cant seem to format the code properly in this issue