I'm trying to detect keypresses on the left and right arrow keys. Here is my current code (nothing gets printed):
this.addEventListener('keypress', event => {
if (event.key == "ArrowLeft") {
console.log("Left key");
} else if (event.key == "ArrowRight") {
console.log("Right key");
}
});
I've tried console.log(event.key) and pressing the directional arrow buttons as well, but again, nothing gets printed.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/1KpsiEP
Comments
Post a Comment