keyboard input refactor