get_char()

Read a keypress and return the resulting character as a string.

Returns:

Name Type Description
char str

the pressed key or the key description (e.g. "home")

Source code in pzp/input_win.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def get_char() -> str:
    """
    Read a keypress and return the resulting character as a string.

    Returns:
        char: the pressed key or the key description (e.g. "home")
    """
    ch: str = getwch()
    if ch == WIN_ESC or ch == NULL:  # When reading arrow/insert/del key, the first call returnx 0xe0
        keys_mapping = KEYS_MAPPING
        while keys_mapping:
            ch = ch + getwch()
            keys_mapping = {k: v for k, v in keys_mapping.items() if k.startswith(ch)}
            if len(keys_mapping) == 1 and next(iter(keys_mapping.keys())) == ch:
                result = next(iter(keys_mapping.values()))
                return result
        return ""
    return ch