|
| 1 | +from collections.abc import Callable, Generator, Iterable, Sequence |
| 2 | +from queue import Queue |
| 3 | +from threading import Event as _UninterruptibleEvent |
| 4 | +from typing import Optional |
| 5 | +from typing_extensions import TypeAlias |
| 6 | + |
| 7 | +from ._canonical_names import all_modifiers as all_modifiers, sided_modifiers as sided_modifiers |
| 8 | +from ._generic import GenericListener as _GenericListener |
| 9 | +from ._keyboard_event import KEY_DOWN as KEY_DOWN, KEY_UP as KEY_UP, KeyboardEvent as KeyboardEvent |
| 10 | + |
| 11 | +_Key: TypeAlias = int | str |
| 12 | +_ScanCodeList: TypeAlias = list[int] | tuple[int, ...] |
| 13 | +_ParseableHotkey: TypeAlias = _Key | list[int | _ScanCodeList] | tuple[int | _ScanCodeList, ...] |
| 14 | +_Callback: TypeAlias = Callable[[KeyboardEvent], Optional[bool]] | Callable[[], Optional[bool]] |
| 15 | +# mypy doesn't support PEP 646's TypeVarTuple yet: https://github.com/python/mypy/issues/12280 |
| 16 | +# _Ts = TypeVarTuple("_Ts") |
| 17 | +_Ts: TypeAlias = tuple[object, ...] |
| 18 | + |
| 19 | +version: str |
| 20 | + |
| 21 | +class _Event(_UninterruptibleEvent): |
| 22 | + def wait(self) -> None: ... # type: ignore[override] # Actual implementation |
| 23 | + |
| 24 | +def is_modifier(key: _Key | None) -> bool: ... |
| 25 | +def key_to_scan_codes(key: _ParseableHotkey, error_if_missing: bool = ...) -> tuple[int, ...]: ... |
| 26 | +def parse_hotkey(hotkey: _ParseableHotkey) -> tuple[tuple[tuple[int, ...], ...], ...]: ... |
| 27 | +def send(hotkey: _ParseableHotkey, do_press: bool = ..., do_release: bool = ...) -> None: ... |
| 28 | + |
| 29 | +press_and_release = send |
| 30 | + |
| 31 | +def press(hotkey: _ParseableHotkey) -> None: ... |
| 32 | +def release(hotkey: _ParseableHotkey) -> None: ... |
| 33 | + |
| 34 | +# is_pressed cannot check multi-step hotkeys, so not using _ParseableHotkey |
| 35 | + |
| 36 | +def is_pressed(hotkey: _Key | _ScanCodeList) -> bool: ... |
| 37 | +def call_later(fn: Callable[..., None], args: _Ts = ..., delay: float = ...) -> None: ... |
| 38 | +def hook(callback: _Callback, suppress: bool = ..., on_remove: Callable[[], None] = ...) -> Callable[[], None]: ... |
| 39 | +def on_press(callback: _Callback, suppress: bool = ...) -> Callable[[], None]: ... |
| 40 | +def on_release(callback: _Callback, suppress: bool = ...) -> Callable[[], None]: ... |
| 41 | +def hook_key(key: _ParseableHotkey, callback: _Callback, suppress: bool = ...) -> Callable[[], None]: ... |
| 42 | +def on_press_key(key: _ParseableHotkey, callback: _Callback, suppress: bool = ...) -> Callable[[], None]: ... |
| 43 | +def on_release_key(key: _ParseableHotkey, callback: _Callback, suppress: bool = ...) -> Callable[[], None]: ... |
| 44 | +def unhook(remove: _Callback) -> None: ... |
| 45 | + |
| 46 | +unhook_key = unhook |
| 47 | + |
| 48 | +def unhook_all() -> None: ... |
| 49 | +def block_key(key: _ParseableHotkey) -> Callable[[], None]: ... |
| 50 | + |
| 51 | +unblock_key = unhook_key |
| 52 | + |
| 53 | +def remap_key(src: _ParseableHotkey, dst: _ParseableHotkey) -> Callable[[], None]: ... |
| 54 | + |
| 55 | +unremap_key = unhook_key |
| 56 | + |
| 57 | +def parse_hotkey_combinations(hotkey: _ParseableHotkey) -> tuple[tuple[tuple[int, ...], ...], ...]: ... |
| 58 | +def add_hotkey( |
| 59 | + hotkey: _ParseableHotkey, |
| 60 | + callback: Callable[..., bool | None], |
| 61 | + args: _Ts = ..., |
| 62 | + suppress: bool = ..., |
| 63 | + timeout: float = ..., |
| 64 | + trigger_on_release: bool = ..., |
| 65 | +) -> Callable[[], None]: ... |
| 66 | + |
| 67 | +register_hotkey = add_hotkey |
| 68 | + |
| 69 | +def remove_hotkey(hotkey_or_callback: _ParseableHotkey | _Callback) -> None: ... |
| 70 | + |
| 71 | +unregister_hotkey = remove_hotkey |
| 72 | +clear_hotkey = remove_hotkey |
| 73 | + |
| 74 | +def unhook_all_hotkeys() -> None: ... |
| 75 | + |
| 76 | +unregister_all_hotkeys = unhook_all_hotkeys |
| 77 | +remove_all_hotkeys = unhook_all_hotkeys |
| 78 | +clear_all_hotkeys = unhook_all_hotkeys |
| 79 | + |
| 80 | +def remap_hotkey( |
| 81 | + src: _ParseableHotkey, dst: _ParseableHotkey, suppress: bool = ..., trigger_on_release: bool = ... |
| 82 | +) -> Callable[[], None]: ... |
| 83 | + |
| 84 | +unremap_hotkey = remove_hotkey |
| 85 | + |
| 86 | +def stash_state() -> list[int]: ... |
| 87 | +def restore_state(scan_codes: Iterable[int]) -> None: ... |
| 88 | +def restore_modifiers(scan_codes: Iterable[int]) -> None: ... |
| 89 | +def write(text: str, delay: float = ..., restore_state_after: bool = ..., exact: bool | None = ...) -> None: ... |
| 90 | +def wait(hotkey: _ParseableHotkey | None = ..., suppress: bool = ..., trigger_on_release: bool = ...) -> None: ... |
| 91 | +def get_hotkey_name(names: Iterable[str] | None = ...) -> str: ... |
| 92 | +def read_event(suppress: bool = ...) -> KeyboardEvent: ... |
| 93 | +def read_key(suppress: bool = ...) -> _Key: ... |
| 94 | +def read_hotkey(suppress: bool = ...) -> str: ... |
| 95 | +def get_typed_strings(events: Iterable[KeyboardEvent], allow_backspace: bool = ...) -> Generator[str, None, None]: ... |
| 96 | +def start_recording( |
| 97 | + recorded_events_queue: Queue[KeyboardEvent] | None = ..., |
| 98 | +) -> tuple[Queue[KeyboardEvent], Callable[[], None]]: ... |
| 99 | +def stop_recording() -> list[KeyboardEvent]: ... |
| 100 | +def record(until: str = ..., suppress: bool = ..., trigger_on_release: bool = ...) -> list[KeyboardEvent]: ... |
| 101 | +def play(events: Iterable[KeyboardEvent], speed_factor: float = ...) -> None: ... |
| 102 | + |
| 103 | +replay = play |
| 104 | + |
| 105 | +def add_word_listener( |
| 106 | + word: str, callback: _Callback, triggers: Sequence[str] = ..., match_suffix: bool = ..., timeout: float = ... |
| 107 | +) -> Callable[[], None]: ... |
| 108 | +def remove_word_listener(word_or_handler: str | _Callback) -> None: ... |
| 109 | +def add_abbreviation( |
| 110 | + source_text: str, replacement_text: str, match_suffix: bool = ..., timeout: float = ... |
| 111 | +) -> Callable[[], None]: ... |
| 112 | + |
| 113 | +register_word_listener = add_word_listener |
| 114 | +register_abbreviation = add_abbreviation |
| 115 | +remove_abbreviation = remove_word_listener |
0 commit comments