Register key code when a key is pressed.