how to detect a keypress in javascript

JavaScript
window.addEventListener("keydown", (event) => {
	console.log(event.key);
});
Source