Javascript DOM MouseEvent shiftKey Property

Introduction

Find out whether or not the "SHIFT" key was pressed when a mouse button is clicked:

View in separate window

<!DOCTYPE html>
<html>
<body onmousedown="isKeyPressed(event)">

<p id="demo"></p>


<script>
function isKeyPressed(event) {//w ww.j a va  2  s .co m
  if (event.shiftKey) {
    document.getElementById("demo").innerHTML = "The SHIFT key was pressed!";
  } else {
    document.getElementById("demo").innerHTML = "The SHIFT key was NOT pressed!";
  }
}
</script>

</body>
</html>

The shiftKey property returns a Boolean value that indicates whether or not the "SHIFT" key was pressed when a mouse event was triggered.

This property is read-only.




PreviousNext

Related