-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
54 lines (34 loc) · 1.36 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "MouseEvent: ctrlKey property"
short-title: ctrlKey
slug: Web/API/MouseEvent/ctrlKey
page-type: web-api-instance-property
browser-compat: api.MouseEvent.ctrlKey
---
{{APIRef("UI Events")}}
The **`MouseEvent.ctrlKey`** read-only property is a boolean value that indicates whether the <kbd>ctrl</kbd> key was pressed or not when a given mouse event occurs.
On Macintosh keyboards, this key is labeled the <kbd>control</kbd> key. Also, note that on a Mac, a click combined with the <kbd>control</kbd> key is intercepted by the operating system and used to open a context menu, so `ctrlKey` is not detectable on click events.
## 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 {{domxref("Element/mousemove_event", "mousemove")}} event.
### 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}`;
}
```
### Result
{{EmbedLiveSample("Examples")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{ domxref("MouseEvent") }}