Refactor keypressing