Javascript DOM TouchEvent altKey Property

Introduction

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

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

Many touch devices do not have an ALT 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 a v a 2s. c o m*/
  if (event.altKey) {
    document.getElementById("demo").innerHTML = "The ALT key was pressed!";
  } else {
    document.getElementById("demo").innerHTML = "The ALT key was NOT pressed!";
  }
}
</script>

</body>
</html>

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

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

This property is read-only.




PreviousNext

Related