You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Document that the Enter key causes the “keypress” event to fire (#37817)
Document that the Enter key causes the keypress event to fire
This change updates the page for the “keypress” event to match actual
behavior in browsers — by changing the page to state that the event
fires when the Enter key is pressed — not only when a key that produces
a character value is pressed.
See w3c/uievents#183 (comment)
and w3c/uievents#266 (comment)
and w3c/uievents#392
Otherwise, without this change, the information on the “keypress” page
incorrectly doesn’t match actual browser behavior — in that the page
states that the “keypress” event fires _only_ when a key that produces a
character value are pressed, while in fact browsers also fire the event
when the Enter key is pressed.
The **`keypress`** event is fired when a key that produces a character value is pressed down.
14
-
15
-
Examples of keys that produce a character value are alphabetic, numeric, and punctuation keys. Examples of keys that don't produce a character value are modifier keys such as <kbd>Alt</kbd>, <kbd>Shift</kbd>, <kbd>Ctrl</kbd>, or <kbd>Meta</kbd>.
13
+
The **`keypress`** event is fired when a [letter, number, punctuation, or symbol](https://w3c.github.io/uievents/#unicode-character-categories) key is pressed, or else when the <kbd>Enter</kbd> key is pressed — including when the <kbd>Enter</kbd> key is pressed in combination with the <kbd>Shift</kbd> key or <kbd>Ctrl</kbd> key. Otherwise, when a modifier key such as the <kbd>Alt</kbd>, <kbd>Shift</kbd>, <kbd>Ctrl</kbd>, <kbd>Meta</kbd>, <kbd>Esc</kbd>, or <kbd>Option</kbd> key is pressed in isolation, the `keypress` event is _not_ fired.
16
14
17
15
> [!WARNING]
18
16
> Since this event has been deprecated, you should use [`beforeinput`](/en-US/docs/Web/API/Element/beforeinput_event) or [`keydown`](/en-US/docs/Web/API/Element/keydown_event) instead.
@@ -71,6 +69,15 @@ _This interface also inherits properties of its parents, {{domxref("UIEvent")}}
71
69
72
70
This example logs the {{domxref("KeyboardEvent.code")}} value whenever you press a key after focussing the {{htmlelement("input")}} element.
73
71
72
+
To see which keys cause a `keypress` event to fire, and which keys don't, try pressing the following:
73
+
74
+
- letter keys, number keys, and punctuation keys
75
+
- symbol keys such as the <kbd>$</kbd>, <kbd>+</kbd>, <kbd>=</kbd>, <kbd>%</kbd>, and <kbd>+</kbd> keys
76
+
- modifier keys such as the <kbd>Alt</kbd>, <kbd>Shift</kbd>, <kbd>Ctrl</kbd>, <kbd>Meta</kbd>, <kbd>Esc</kbd>, <kbd>Option</kbd>, or <kbd>⌘</kbd> keys
77
+
- the <kbd>Enter</kbd> key
78
+
- the <kbd>Enter</kbd> key in combination with the <kbd>Shift</kbd> or <kbd>Ctrl</kbd> keys
79
+
- the <kbd>Enter</kbd> key in combination with modifier keys other than the <kbd>Shift</kbd> or <kbd>Ctrl</kbd> keys
80
+
74
81
```html
75
82
<div>
76
83
<labelfor="sample">Focus the input and type something:</label>
0 commit comments