added logic for keypress