def key_printer(self, win, key): """Print required key to terminal. Args: win (any): Curses window object. key (string): Individual characters are returned as 1-character strings, and special keys such as function keys return longer strings containing a key name such as KEY_UP or ^G. """ # Reset test if is_escape(key): self.reset_test() elif is_ctrl_c(key): sys.exit(0) # Handle resizing elif is_resize(key): self.resize(win) # Check for backspace elif is_backspace(key): self.erase_key() # Ignore spaces at the start of the word (Plover support) elif key == " ": if self.current_word != "": self.check_word() elif is_valid_initial_key(key): self.appendkey(key) # Update state of window self.update_state(win)
def typing_mode(self, win, key): """Start recording typing session progress. Args: win (any): Curses window. key (string): First typed character of the session. """ # Note start time when first valid key is pressed if not self.first_key_pressed and is_valid_initial_key(key): self.start_time = time.time() self.first_key_pressed = True if is_resize(key): self.resize(win) if not self.first_key_pressed: return self.key_strokes.append([time.time(), key]) self.print_realtime_wpm(win) self.key_printer(win, key)