MouseEvent: ctrlKey-Eigenschaft

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.

Die schreibgeschützte Eigenschaft MouseEvent.ctrlKey ist ein boolescher Wert, der angibt, ob die ctrl-Taste gedrückt war, als ein bestimmtes Mausereignis auftrat.

Auf Macintosh-Tastaturen wird diese Taste als control-Taste bezeichnet. Beachten Sie auch, dass auf einem Mac ein Klick in Kombination mit der control-Taste vom Betriebssystem abgefangen und zum Öffnen eines Kontextmenüs verwendet wird. Daher ist ctrlKey bei Klickereignissen nicht erkennbar.

Wert

Ein boolescher Wert, bei dem true anzeigt, dass die Taste gedrückt ist, und false anzeigt, dass die Taste nicht gedrückt ist.

Beispiele

Dieses Beispiel protokolliert die ctrlKey-Eigenschaft, wenn Sie ein mousemove-Ereignis auslösen.

HTML

html
<p id="log">The ctrl key was pressed while the cursor was moving: false</p>

JavaScript

js
const log = document.querySelector("#log");
window.addEventListener("mousemove", logKey);

function logKey(e) {
  log.textContent = `The ctrl key was pressed while the cursor was moving: ${e.ctrlKey}`;
}

Ergebnis

Spezifikationen

Specification
UI Events
# dom-mouseevent-ctrlkey

Browser-Kompatibilität

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
ctrlKey

Legend

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

Full support
Full support

Siehe auch