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

+2

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

+9

Here read this: https://www.javascripttutorial.net/javascript-dom/javascript-keyboard-events/ This hopefully will answer your question!

+5

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

+5

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.

+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😊