window.addEventListener("keyup", function(event) { if (event.key == 'Escape'/*Your key*/) { // do something } })