Extract KeyboardInput class.

Fix bug with keyboard repeat making it look like a key was pressed
multiple times.