document.addEventListener('keyup', event => { if (String.fromCharCode(event.keyCode).match(/(w|s)/g)) { //pressed key is a char } else { //pressed key is a non-char //e.g. 'esc', 'backspace', 'up arrow' } });