MouseEvent: ctrlKey プロパティ
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.ctrlKey
は読み取り専用のプロパティで、このマウスイベントが発生した際に Ctrl キーが押されていたかどうかを示す論理値です。
Macintosh のキーボードでは、このキーは control キーと表記されています。また、 Mac では control キーと組み合わせたクリックは、オペレーティングシステムに拾われてコンテキストメニューを開くのに使われるので、 ctrlKey
はクリックイベントで検出されないことに注意してください。
値
論理値で、 true
はキーが押されていたことを示し、 false
はキーが押されていなかったことを示します。
例
この例では、 mousemove
イベントを発生させた際に ctrlKey
プロパティを記録します。
HTML
html
<p id="log">カーソルが動いていたときに Ctrl キーが押されていた: false</p>
JavaScript
js
const log = document.querySelector("#log");
window.addEventListener("mousemove", logKey);
function logKey(e) {
log.textContent = `カーソルが動いていたときに Ctrl キーが押されていた: ${e.ctrlKey}`;
}
結果
仕様書
Specification |
---|
UI Events # dom-mouseevent-ctrlkey |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
ctrlKey |
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.