Keypress handling functions.