MouseEvent: shiftKey property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The MouseEvent.shiftKey
read-only property is a boolean value that indicates whether the shift key was pressed or not when a given mouse event occurs.
Value
A boolean value, where true
indicates that the key is pressed, and false
indicates that the key is not pressed.
Examples
This example logs the shiftKey
property when you trigger a click
event.
HTML
html
<p>Click anywhere to test the <code>shiftKey</code> property.</p>
<p id="log"></p>
JavaScript
js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);
function logKey(e) {
log.textContent = `The shift key is pressed: ${e.shiftKey}`;
}
Result
Specifications
Specification |
---|
UI Events # dom-mouseevent-shiftkey |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
shiftKey |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.