Keyboard event handling | Sololearn: Learn to code for FREE!


Keyboard event handling

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

8/8/2020 10:48:12 AM

Goke Ekundayo

6 Answers

New Answer


Here read this: This hopefully will answer your question!


May the audience know which programming language is preferred by you?


then write it into the keywords because it is important. In the case of JavaScript I am not experienced enough to be able to help you.


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


window.onkeydown = function(e) { console.log("Key pressed: " + e.key); }; // Also look at the first answer’s compatibility notes at the bottom:


Thanks everyone, i get it now😊