MouseEvent: ctrlKey property

The MouseEvent.ctrlKey read-only property is a boolean value that indicates whether the ctrl key was pressed or not when a given mouse event occurs.

Note: On Macintosh keyboards, this key is the control key.

Value

A boolean value, where true indicates that the key is pressed, and false indicates that the key is not pressed.

Examples

This example logs the ctrlKey property when you trigger a click event.

HTML

<p>Click anywhere to test the <code>ctrlKey</code> property.</p>
<p id="log"></p>

JavaScript

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

function logKey(e) {
  log.textContent = `The ctrl key is pressed: ${e.ctrlKey}`;
}

Result

Specifications

Specification
UI Events
# dom-mouseevent-ctrlkey

Browser compatibility

BCD tables only load in the browser

See also