Javascript DOM TouchEvent metaKey Property

Introduction

Find out whether or not the "META" key was pressed when you touch the screen:

Try holding down the META key when you touch the document.

Many touch devices do not have a META key.

View in separate window

<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body ontouchstart="isKeyPressed(event)">
<p>Touch somewhere in this document.</p>

<p id="demo"></p>
<script>
function isKeyPressed(event) {/*  w  w w .  j  av a 2  s . c  o  m*/
  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>

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

Many touch devices do not have an "META" key, and will always return false.

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

This property is read-only.




PreviousNext

Related