Answers for "handle esc press js"

2

handle esc press js

//Check if the key is the Escape key, also known as 27 in the ASCII table
const pressEsc = (event) => {
	if(event.key === "Escape"){
    	console.log("You pressed Esc button")
    }
}

//Listen to the global keydown, the callback function will give us the wanted result
window.addEventListener("keydown", pressEsc)
Posted by: Guest on April-27-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language