def add_word_listener(word, callback, triggers=['<STR_LIT>'], match_suffix=False, timeout=<NUM_LIT:2>):
state = _State()<EOL>state.current = '<STR_LIT>'<EOL>state.time = -<NUM_LIT:1><EOL>def handler(event):<EOL><INDENT>name = event.name<EOL>if event.event_type == KEY_UP or name in all_modifiers: return<EOL>if timeout and event.time - state.time > timeout:<EOL><INDENT>state.current = '<STR_LIT>'<EOL><DEDENT>state.time = event.time<EOL>matched = state.current == word or (match_suffix and state.current.endswith(word))<EOL>if name in triggers and matched:<EOL><INDENT>callback()<EOL>state.current = '<STR_LIT>'<EOL><DEDENT>elif len(name) > <NUM_LIT:1>:<EOL><INDENT>state.current = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>state.current += name<EOL><DEDENT><DEDENT>hooked = hook(handler)<EOL>def remove():<EOL><INDENT>hooked()<EOL>del _word_listeners[word]<EOL>del _word_listeners[handler]<EOL>del _word_listeners[remove]<EOL><DEDENT>_word_listeners[word] = _word_listeners[handler] = _word_listeners[remove] = remove<EOL>return remove<EOL>
Invokes a callback every time a sequence of characters is typed (e.g. 'pet')
and followed by a trigger key (e.g. space). Modifiers (e.g. alt, ctrl,
shift) are ignored.

- `word` the typed text to be matched. E.g. 'pet'.
- `callback` is an argument-less function to be invoked each time the word
is typed.
- `triggers` is the list of keys that will cause a match to be checked. If
the user presses some key that is not a character (len>1) and not in
triggers, the characters so far will be discarded. By default the trigger
is only `space`.
- `match_suffix` defines if endings of words should also be checked instead
of only whole words. E.g. if true, typing 'carpet'+space will trigger the
listener for 'pet'. Defaults to false, only whole words are checked.
- `timeout` is the maximum number of seconds between typed characters before
the current word is discarded. Defaults to 2 seconds.

Returns the event handler created. To remove a word listener use
`remove_word_listener(word)` or `remove_word_listener(handler)`.

Note: all actions are performed on key down. Key up events are ignored.
Note: word mathes are **case sensitive**.