refactoring keyCode check