smarter event handling, keypress only works once