Improved keypress handling.