The keypress event is fired when a key is pressed down, and that key normally produces a character value (use input instead).
General info
- Specification
- DOM L3
- Interface
- KeyboardEvent
- Bubbles
- Yes
- Cancelable
- Yes
- Target
- Document, Element
- Default Action
- Varies: keypressevent; launch text composition system;blurandfocusevents;DOMActivateevent; other event
Properties
| Property | Type | Description | 
|---|---|---|
| targetRead only | EventTarget | The event target (the topmost target in the DOM tree). | 
| typeRead only | DOMString | The type of event. | 
| bubblesRead only | Boolean | Whether the event normally bubbles or not | 
| cancelableRead only | Boolean | Whether the event is cancellable or not? | 
| viewRead only | WindowProxy | document.defaultView(windowof the document) | 
| detailRead only | long(float) | 0. | 
| target | EventTarget (DOM element) | Focused element processing the key event, root element if no suitable input element focused. | 
| charRead only  Unimplemented (see bugĀ 680830) | DOMString (string) | The character value of the key. 
    If the key corresponds to a printable character, this value is a non-empty Unicode string containing that character.
    If the key doesn't have a printable representation, this is an empty string.
    See key names and char values for the detail. 
      Note: If the key is used as a macro that inserts multiple characters, this attribute's value is the entire string, not just the first character.
     | 
| keyUnimplemented (see bugĀ 680830) | DOMString (string) | The key value of the key represented by the event.
    If the value has a printed representation, this attribute's value is the same as the charattribute.
    Otherwise, it's one of the key value strings specified in {{ anch("Key values") }}.
    If the key can't be identified, this is the string "Unidentified".
    See key names and char values for the detail.
    Read Only. | 
| charCodeRead only | Unsigned long (int) | The Unicode reference number of the key; this attribute is used only by the keypressevent.
    For keys whosecharattribute contains multiple characters, this is the Unicode value of the first character in that attribute.
      Warning: This attribute is deprecated; you should use  charinstead, if available. | 
| keyCodeRead only | Unsigned long (int) | A system and implementation dependent numerical code identifying the unmodified value of the pressed key.
    This is usually the decimal ASCII ({{ RFC(20) }}) or Windows 1252 code corresponding to the key; see {{ anch("Virtual key codes") }} for a list of common values.
    If the key can't be identified, this value is 0. 
      Warning: This attribute is deprecated; you should use  keyinstead, if available. | 
| whichRead only | Unsigned long (int) | A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same as keyCode.
      Warning: This attribute is deprecated; you should use  keyinstead, if available. | 
| locationRead only | long (float) | The location of the key on the device. | 
| repeatRead only  Unimplemented | boolean | trueif a key has been depressed long enough to trigger key repetition, otherwisefalse. | 
| localeRead only  Unimplemented | string | The language code for the key event, if available; otherwise, the empty string. | 
| ctrlKeyRead only | boolean | trueif the control key was down when the event was fired.falseotherwise. | 
| shiftKeyRead only | boolean | trueif the shift key was down when the event was fired.falseotherwise. | 
| altKeyRead only | boolean | trueif the alt key was down when the event was fired.falseotherwise. | 
| metaKeyRead only | boolean | trueif the meta key was down when the event was fired.falseotherwise. | 
Notes
Chrome does not fire the keypress event for known keyboard shortcuts (reference). Which keyboard shortcuts are known depends on the user's system. Use the keydown event to implement keyboard shortcuts.
Related Events
Document Tags and Contributors
                       Contributors to this page: 
        bunnybooboo, 
        Konrud, 
        jwhitlock, 
        Dikrib, 
        cvrebert, 
        teoli, 
        Sheppy, 
        ethertank, 
        circusbred, 
        louisremi
                    
                    
                       Last updated by:
                      bunnybooboo,