event handler for keypresses working as intended