js event .key code example
Example 1: js when key is pressed
document.addEventListener("keypress", function(event) {
// do stuff
});
Example 2: javascript keyboard events
document.addEventListener("keydown", function(event) {
if (event.keyCode == 32) {
console.log("Space was pressed!");
}
});