+ 2
Keyboard event handling
How can i trigger an event when any or a particular key on the keyboard is pressed in JavaScript
4 ответов
+ 9
Here read this:
https://www.javascripttutorial.net/javascript-dom/javascript-keyboard-events/
This hopefully will answer your question!
+ 5
onkeydown - When a user is pressing/holding down a key
onkeyup - When the user releases a key
onkeypress - When a user is pressing/holding down a key
+ 3
window.onkeydown = function(e) {
console.log("Key pressed: " + e.key);
};
// Also look at the first answer’s compatibility notes at the bottom: https://stackoverflow.com/questions/905222/enter-key-press-event-in-javascript
+ 3
Thanks everyone, i get it now😊