Improve and streamline key-handling logic.

Moving most logic into the private handleKey() function.
Fire key-up events for all currently pressed keys.

Closes #353.