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

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


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

<!DOCTYPE html>
      <input type = "text" onkeydown = "funcShiftKey(event)">
      <div id = "res">Press any key</div>
         function funcShiftKey(event) {
            var val = document.getElementById("res");
            if (event.shiftKey) {
               val.innerHTML = "SHIFT key: Pressed";
            } else {
               val.innerHTML = "SHIFT key: NOT Pressed";

Updated on: 23-May-2020


Kickstart Your Career

Get certified by completing the course

Get Started