--- title: MouseEvent.shiftKey slug: Web/API/MouseEvent/shiftKey translation_of: Web/API/MouseEvent/shiftKey ---

{{APIRef("DOM Events")}}

MouseEvent.shiftKey 是只读属性,指出触发鼠标事件时是否按住了 shift

Syntax

var shiftKeyPressed = instanceOfMouseEvent.shiftKey

Return value

A boolean

Example

<html>
<head>
<title>shiftKey example</title>

<script type="text/javascript">

function showChar(e){
  alert(
    "Key Pressed: " + String.fromCharCode(e.charCode) + "\n"
    + "charCode: " + e.charCode + "\n"
    + "SHIFT key pressed: " + e.shiftKey + "\n"
    + "ALT key pressed: " + e.altKey + "\n"
  );
}

</script>
</head>

<body onkeypress="showChar(event);">
<p>Press any character key, with or without holding down
 the SHIFT key.<br />
You can also use the SHIFT key together with the ALT key.</p>
</body>
</html>

Specifications

Specification Status Comment
{{SpecName('DOM3 Events','#widl-MouseEvent-shiftKey','MouseEvent.shiftKey')}} {{Spec2('DOM3 Events')}} No change from {{SpecName('DOM2 Events')}}.
{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.shiftKey')}} {{Spec2('DOM2 Events')}} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Edge Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}} {{CompatVersionUnknown()}}
Feature Edge Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }} {{ CompatUnknown() }}

See also