Moved some keyboard events to the main loop.

Moved keyboard handlers for 'q' and 'f' to the main loop so that they
work in all screens.