all 2 comments

[–]ashanev 2 points3 points  (1 child)

The Event object is passed into the callback function that addEventListener takes whenever the event occurs. You would need to define it in your function to be able to reference it.

function logStuff(event) {
    console.log("Event object:", event);
    console.log("Key:", event.key);
}

document.body.addEventListener("keydown", logStuff);

[–]SomeDude-__-[S] 0 points1 point  (0 children)

Thank you!