refactor keyboard control