Answers for "add event listener to keyboard"

3

javascript keyboard events

document.addEventListener("keydown", function(event) {
  if (event.keyCode == 32) {
    console.log("Space was pressed!");
  }
});
Posted by: Guest on May-21-2020
0

adding event listener keypress event in javascript

let msg = document.getDocumentById('#message');

msg.addEventListener("keydown", (event) => {
    // handle keydown
});

msg.addEventListener("keypress", (event) => {
    // handle keypress
});

msg.addEventListener("keyup", (event) => {
    // handle keyup
});
Posted by: Guest on November-18-2020
-1

event listener js keydown not working

window.addEventListener("keydown", function(e){}, true);
//true makes it work
Posted by: Guest on December-20-2020

Browse Popular Code Answers by Language