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

HTMLJavascriptProgramming Scripts

The ctrlKey property is used to show whether the CTRL key is pressed or not when key event was triggered. You can try to run the following code to learn how to implement a ctrlKey property in JavaScript −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <input type = "text" onkeydown = "funcCtrlKey(event)">
      <div id = "res">Press any key</div>

      <script>
            function funcCtrlKey(event) {
            var val = document.getElementById("res");

            if (event.ctrlKey) {
               val.innerHTML = "CTRL key: Pressed";
            } else {
               val.innerHTML = "CTRL key: NOT Pressed";
            }
         }
      </script>
   </body>
   
</html>
raja
Published on 26-Feb-2018 16:40:09
Advertisements