add keydown controlling function