onkeydown specific key code example
Example 1: js keyboard input
document.addEventListener('keydown', function(event) {
if(event.keyCode == 37) {
alert('Left was pressed');
}
else if(event.keyCode == 39) {
alert('Right was pressed');
}
});
Example 2: if event keycode and click
function advance(event) {
if (event instanceof MouseEvent) {
console.log('clicked');
} else if (event instanceof KeyboardEvent && event.keyCode === 13) {
console.log('enter');
}
}
window.addEventListener('keypress', advance);