Updated function to fire on key press