def get_typed_strings(events, allow_backspace=True):
backspace_name = '<STR_LIT>' if _platform.system() == '<STR_LIT>' else '<STR_LIT>'<EOL>shift_pressed = False<EOL>capslock_pressed = False<EOL>string = '<STR_LIT>'<EOL>for event in events:<EOL><INDENT>name = event.name<EOL>if event.name == '<STR_LIT>':<EOL><INDENT>name = '<STR_LIT:U+0020>'<EOL><DEDENT>if '<STR_LIT>' in event.name:<EOL><INDENT>shift_pressed = event.event_type == '<STR_LIT>'<EOL><DEDENT>elif event.name == '<STR_LIT>' and event.event_type == '<STR_LIT>':<EOL><INDENT>capslock_pressed = not capslock_pressed<EOL><DEDENT>elif allow_backspace and event.name == backspace_name and event.event_type == '<STR_LIT>':<EOL><INDENT>string = string[:-<NUM_LIT:1>]<EOL><DEDENT>elif event.event_type == '<STR_LIT>':<EOL><INDENT>if len(name) == <NUM_LIT:1>:<EOL><INDENT>if shift_pressed ^ capslock_pressed:<EOL><INDENT>name = name.upper()<EOL><DEDENT>string = string + name<EOL><DEDENT>else:<EOL><INDENT>yield string<EOL>string = '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT>yield string<EOL>
Given a sequence of events, tries to deduce what strings were typed.
Strings are separated when a non-textual key is pressed (such as tab or
enter). Characters are converted to uppercase according to shift and
capslock status. If `allow_backspace` is True, backspaces remove the last
character typed.

This function is a generator, so you can pass an infinite stream of events
and convert them to strings in real time.

Note this functions is merely an heuristic. Windows for example keeps per-
process keyboard state such as keyboard layout, and this information is not
available for our hooks.

    get_type_strings(record()) #-> ['This is what', 'I recorded', '']