KeyboardEvent: shiftKey property
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{APIRef("UI Events")}}
The **KeyboardEvent.shiftKey** read-only property is a boolean value that indicates if the <kbd>shift</kbd> key was pressed (true) or not (false) when the event occurred.
The pressing of the shift key may change the {{domxref("KeyboardEvent/key", "key")}} of the event too. For example, pressing <kbd>B</kbd> generates key: "b", while simultaneously pressing <kbd>Shift</kbd> generates key: "B".
When the <kbd>Shift</kbd> key itself is pressed or released, this property is true for its {{domxref("Element/keydown_event", "keydown")}} event and false for its {{domxref("Element/keyup_event", "keyup")}} event, because both events fire _after_ the state change.
Value
A boolean value.
Examples
<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>
<pre id="output"></pre>const output = document.getElementById("output");
function showChar(e) {
output.textContent = `Key KeyDown: "${e.key}"
SHIFT key KeyDown: ${e.shiftKey}
`;
}
document.addEventListener("keydown", showChar);{{EmbedLiveSample("examples", "", "400")}}
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{ domxref("KeyboardEvent") }}