Abstracting key press checking code.