What is the role of Keyboard Event altKey Property in JavaScript?

HTMLJavascriptProgramming Scripts

The altkey property is used to show whether ALT key is pressed or not when key event was triggered.


You can try to run the following code to learn how to implement altKey property in JavaScript.

<!DOCTYPE html>
      <input type = "text" onkeydown = "funcAltKey(event)">
      <div id = "res"> Press any key </div>
         function funcAltKey(event) {
            var val = document.getElementById("res");
            if (event.altKey) {
               val.innerHTML = "ALT key: Pressed";
            } else {
               val.innerHTML = "ALT key: NOT Pressed";
Published on 26-Feb-2018 12:26:48