smarter keypress handling