Improve keyboard input handling