do something on keyboard click javascript code example
Example 1: how to detect a keypress in javascript
window.addEventListener("keydown", (event) => {
console.log(event.key);
});
Example 2: how do i listen to a keypress in javascript
let b = document.getElementById("body"); //making var for body
b.addEventListener("keydown", (evt) => {//when this happens
console.log(evt.keyCode); //log keycode
});