Keyboard handling: use a switch rather than a bunch of if statements