+ 2

Keyboard event handling

How can i trigger an event when any or a particular key on the keyboard is pressed in JavaScript

8th Aug 2020, 10:48 AM
Goke Ekundayo
Goke Ekundayo - avatar
4 Answers
+ 9
Here read this: https://www.javascripttutorial.net/javascript-dom/javascript-keyboard-events/ This hopefully will answer your question!
8th Aug 2020, 11:53 PM
toto
toto - avatar
+ 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
8th Aug 2020, 11:36 AM
Nyakotey🇬🇭đŸŽč
Nyakotey🇬🇭đŸŽč - avatar
+ 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
9th Aug 2020, 8:12 AM
Rowsej
Rowsej - avatar
+ 3
Thanks everyone, i get it now😊
9th Aug 2020, 9:23 AM
Goke Ekundayo
Goke Ekundayo - avatar