keypress - Detecting arrow key presses in JavaScript

Опубликовано: 14 Январь 2025
на канале: Code Samples
546
7

#short
#javascript
#keypress
#keyboard-events
How do I detect when one of the arrow keys are pressed? I used this to find out:
function checkKey(e) {
var event = window.event ? window.event : e;
console.log(event.keyCode)
}

Though it worked for every other key, it didn't for arrow keys (maybe because the browser is supposed to scroll on these keys by default).