Pull keypress-handling into its own method.

Fixes #2.