Javascript DOM TouchEvent shiftKey Property

Introduction

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

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

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   ww w.j  ava 2s  . c  o  m*/
  if (event.shiftKey) {
    document.getElementById("demo").innerHTML = "The SHIFT key was pressed!";
  } else {
    document.getElementById("demo").innerHTML = "The SHIFT key was NOT pressed!";
  }
}
</script>

</body>
</html>

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

This property is read-only.




PreviousNext

Related