Refactor keyboard events