diff options
| author | Scott Gasch <[email protected]> | 2022-05-24 16:13:32 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-05-24 16:13:32 -0700 |
| commit | c08841600a2f61049cdb1a152407a1fb8ca129a5 (patch) | |
| tree | 8ea28ea1d85dd2080292a372f989e4b3154bc278 /input_utils.py | |
| parent | a778719a55da82f5a3d1ca5cecd9041530d4d6e9 (diff) | |
Add method to get up/down/enter keystrokes.
Diffstat (limited to 'input_utils.py')
| -rw-r--r-- | input_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/input_utils.py b/input_utils.py index 5e36db1..d958db2 100644 --- a/input_utils.py +++ b/input_utils.py @@ -85,6 +85,23 @@ def press_any_key( return single_keystroke_response(None, prompt=prompt, timeout_seconds=timeout_seconds) +def up_down_enter() -> Optional[str]: + os_special_keystrokes = [3, 26] # ^C, ^Z + while True: + key = readchar.readkey() + if len(key) == 1: + if ord(key) in os_special_keystrokes: + return None + if ord(key) == 13: + return 'enter' + elif len(key) == 3: + if ord(key[0]) == 27 and ord(key[1]) == 91: + if ord(key[2]) == 65: + return "up" + elif ord(key[2]) == 66: + return "down" + + def keystroke_helper() -> None: """Misc util to watch keystrokes and report what they were.""" |
