Added valid key code check and defaults for direction and position.