Javascript DOM KeyboardEvent getModifierState() Method is shift key pressed

Introduction

Is the shift key being pressed down?

var x = event.getModifierState("Shift");

Write som text in the input field, then press down the Shift key and write some more text in the input field:

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="text" size="40" onkeydown="myFunction(event)">
<p id="demo"></p>

<script>
function myFunction(event) {/*from w ww.  j  a v a2 s . c  om*/
  var x = event.getModifierState("Shift");
  document.getElementById("demo").innerHTML = "Pressing the shift key: " + x;
}
</script>
</body>
</html>



PreviousNext

Related