shiftKey property

Retrieves the state of the SHIFT key. For the standards based property, see shiftKey.

Syntax

JavaScript

p = object.shiftKey

 

Property values

Type: Boolean

false (false)

SHIFT key is not pressed.

true (true)

SHIFT key is pressed.

Examples

This example demonstrates how to retrieve the state of the SHIFT key. Any key pressed fires the onkeydown event handler, enabling you to retrieve the state of the SHIFT key. The onkeyup event handler returns true when any key is pressed and released while the SHIFT key is pressed. Whenever the SHIFT key is released, the event handler returns false. The onkeypress event handler only fires when the user presses an alphanumeric key—it will not fire if the SHIFT key is pressed.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/shiftKey.htm


<html>
.
.
.        
<body onkeydown="okd.innerText=event.shiftKey;" 
      onkeypress="okp.innerText=event.shiftKey;"
      onkeyup="oku.innerText=event.shiftKey;">

State of SHIFT key from the onkeydown event handler: 
<span id="okd" class="b"></span><br />
State of SHIFT key from the onkeyup event handler: 
<span id="oku" class="b"></span><br />
State of SHIFT key from the onkeypress event handler: 
<span id="okp" class="b"></span>
.
.
.
</body>
</html>

See also

event
shiftLeft

 

 

Show:
© 2014 Microsoft