Keyboard events in JavaScript - keydown
by danielkwood
HTML
<html>
<head>
<title>Keyboard events in JavaScript</title>
</head>
<body>
<p>Press any key</p>
<p id="result"></p>
</body>
</html>
JavaScript
// You can use the keydown or keyup events for key presses
window.addEventListener("keydown", function(event) {
document.querySelector("#result").innerHTML = "You pressed " + event.key;
});