started a reorganizing of the main input loop

The aim is to better separate different states, in preparation
for things like text input.