MouseEvent: shiftKey プロパティ

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.

MouseEvent.shiftKey は読み取り専用のプロパティで、このマウスイベントが発行されたときに shift キーが押されていたかどうかを示す論理値です。

論理値で、 true はキーが押されていたことを示し、 false はキーが押されていなかったことを示します。

この例では、 click イベントを発生させた際に shiftKey プロパティを記録します。

HTML

html
<p>
  <code>shiftKey</code> プロパティを試験するためにどこかをクリックしてください。
</p>
<p id="log"></p>

JavaScript

js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);

function logKey(e) {
  log.textContent = `Shift キーの押下状態: ${e.shiftKey}`;
}

結果

仕様書

Specification
UI Events
# dom-mouseevent-shiftkey

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
shiftKey

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報