Javascript DOM MouseEvent metaKey Property

Introduction

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

View in separate window

<!DOCTYPE html>
<html>
<body onmousedown="isKeyPressed(event)">
<p>Click somewhere in the document. </p>

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


<script>
function isKeyPressed(event) {//from  www .jav  a 2  s . com
  if (event.metaKey) {
    document.getElementById("demo").innerHTML = "The META key was pressed!";
  } else {
    document.getElementById("demo").innerHTML = "The META key was NOT pressed!";
  }
}
</script>

</body>
</html>

Definition and Usage

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

On Mac keyboards, the META key is represented by the the "Command/Cmd" key.

This property is read-only.




PreviousNext

Related