-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
69 lines (54 loc) · 1.55 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "KeyboardEvent: shiftKey property"
short-title: shiftKey
slug: Web/API/KeyboardEvent/shiftKey
page-type: web-api-instance-property
browser-compat: api.KeyboardEvent.shiftKey
---
{{APIRef("UI Events")}}
The **`KeyboardEvent.shiftKey`** read-only property is a
boolean value that indicates if the <kbd>shift</kbd> key was pressed
(`true`) or not (`false`) when the event occurred.
The pressing of the shift key may change the {{domxref("KeyboardEvent/key", "key")}} of the event too. For example, pressing <kbd>B</kbd> generates `key: "b"`, while simultaneously pressing <kbd>Shift</kbd> generates `key: "B"`.
## Value
A boolean value.
## Examples
```html
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>shiftKey example</title>
<script>
function showChar(e) {
alert(
"Key Pressed: " +
String.fromCharCode(e.charCode) +
"\n" +
"charCode: " +
e.charCode +
"\n" +
"SHIFT key pressed: " +
e.shiftKey +
"\n" +
"ALT key pressed: " +
e.altKey +
"\n",
);
}
</script>
</head>
<body onkeypress="showChar(event);">
<p>
Press any character key, with or without holding down the SHIFT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{ domxref("KeyboardEvent") }}