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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
altKey |
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.