Handle more details about keypresses.

The important detail it handles is if the key was pressed or if it was
released. Until now, it would simulate a key press and release at once. Now
they can happen separately. This makes important things like shift+arrows work
properly.