Javascript DOM TouchEvent ctrlKey Property

Introduction

Find out whether or not the "CTRL" key was pressed when you touch the screen.

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

Many touch devices do not have a CTRL 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) {//from w  w  w.  j  ava2  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 touch event was triggered.

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

This property is read-only.




PreviousNext

Related