KeyEvent key Property - Check if the user presses the "A" key: - Javascript DOM

Javascript examples for DOM:Key Event

Description

KeyEvent key Property - Check if the user presses the "A" key:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" size="40" onkeydown="myFunction(event)">

<script>
function myFunction(event) {/*from w  w w.  j a v a  2 s  .  c o  m*/
    var x = event.key;
    if (x == "a" || x == "A") {
        console.log("You pressed the 'A' key!");
    }
}
</script>

</body>
</html>

Related Tutorials