// Add event listener on keydown
document.addEventListener('keydown', (event) => {
var name = event.key;
var code = event.code;
// Alert the key name and key code on keydown
alert(`Key pressed ${name}
Key code value: ${code}`);
}, false);
window.addEventListener("keyup", function(event) {
if (event.key == 'Escape'/*Your key*/) {
// do something
}
})