KeyEvent keyCode Property - Check if the user presses the Escape key: - Javascript DOM

Javascript examples for DOM:Key Event

Description

KeyEvent keyCode Property - Check if the user presses the Escape key:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" size="50" onkeydown="keyCode(event)">

<script>
function keyCode(event) {//  www.j a  va2s  .co  m
    var x = event.keyCode;
    if (x == 27) {
        console.log("You pressed the Escape key!");
    }
}
</script>

</body>
</html>

Related Tutorials