Javascript DOM MouseEvent getModifierState() Method check shift key

Introduction

Is the shift key being pressed down?

var x = event.getModifierState("Shift");

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" size="40" onmousedown="myFunction(event)">
<p id="demo"></p>

<script>
function myFunction(event) {/*www  .j  a v a 2 s .c om*/
  var x = event.getModifierState("Shift");
  document.getElementById("demo").innerHTML = "Pressing the shift key: " + x;
}
</script>

</body>
</html>



PreviousNext

Related