MouseEvent: altKey プロパティ

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.altKey は読み取り専用のプロパティでありマウスイベントが発行されたときに alt キーが押されていたかどうかを論理値で示します。

オペレーティングシステムによっては、ブラウザーがいつでも alt キーを検出できるとは限りらないことに注意してください。 例えば、一部の Linux では、 alt キーを押しながらマウスの左クリックが、ウィンドウの移動またはリサイズに使われています。

メモ: Macintosh のキーボードでは、このキーは option キーとも呼ばれています。

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

この例は、 click イベントが発行されたときに altKey プロパティを記録します。

HTML

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

JavaScript

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

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

結果

仕様書

Specification
UI Events
# dom-mouseevent-altkey

ブラウザーの互換性

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
altKey

Legend

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

Full support
Full support

関連情報