keydown eventlistener in javascript code example
Example 1: keydown event in javascript
document.addEventListener("keydown", function(event) {
if (event.keyCode == 32) {
console.log("Space was pressed!");
}
});
Example 2: keydown events
document.addEventListener('keydown', logKey);
function logKey(e) {
log.textContent += ` ${e.code}`;
}