onkeydown code example
Example 1: javascript keydown
document.addEventListener("keydown", function(event) {
if (event.keyCode == 32) {
console.log("Space was pressed!");
}
});
Example 2: javascript onkeydown
<input type="text" onkeydown="myFunction()">
Example 3: keydown events
eventTarget.addEventListener("keydown", event => {
if (event.isComposing || event.keyCode === 229) {
return;
}
// do something
});
Example 4: onkeyup
A function is triggered when the user releases a key in the input field