1document.addEventListener("keydown", function(event) {
2 if (event.keyCode == 32) {
3 console.log("Space was pressed!");
4 }
5});
1document.addEventListener("keydown", function(event) {
2 console.log(`Key pressed: ${event.key}`);
3 // event.key is a string representing which key has been pressed
4});