Cleaned up the keyboard event code a bit.