Javascript DOM MouseEvent ctrlKey Property

Introduction

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

Click somewhere in the document.

View in separate window

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

<p id="demo"></p>
<script>
function isKeyPressed(event) {// w  w  w  .  ja  va2 s .c  o  m
  if (event.ctrlKey) {
    document.getElementById("demo").innerHTML = "The CTRL key was pressed!";
  } else {
    document.getElementById("demo").innerHTML = "The CTRL key was NOT pressed!";
  }
}
</script>

</body>
</html>

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

This property is read-only.

Possible values:

  • true - The ctrl key was pressed
  • false - The ctrl key was not pressed



PreviousNext

Related