Tweaked keyboard input routine