4 out of 5 rated this helpful - Rate this topic

shiftKey Property

Gets the state of the SHIFT key.

Syntax

[ bKey = ] object.shiftKey

Possible Values

bKey Boolean that receives one of the following values.
false
SHIFT key is not pressed.
true
SHIFT key is pressed.

The property is read-only. The property has no default value.

DHTML expressions can be used in place of the preceding value(s). As of Internet Explorer 8, expressions are supported in IE7 Standards mode and IE5 (Quirks) mode only. For more information, see About Dynamic Properties and Defining Document Compatibility.

Example

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.


<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>

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

Standards Information

There is no public standard that applies to this property.

Applies To

event, Event Constructor

See Also

shiftLeft
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
documentation question
COMPARE: ctrlKey documentation claims writeable (but breaks its event handler).