Movatterモバイル変換


[0]ホーム

URL:


  1. Веб-технологии для разработчиков
  2. Интерфейсы веб API
  3. Element
  4. keypress

This page was translated from English by the community.Learn more and join the MDN Web Docs community.

View in EnglishAlways switch to English

keypress

Событиеkeypress происходит когда нажимается символьная клавиша, то есть клавиша которая создаёт символ. Пример таких клавиш это буквы, цифры, знаки пунктуации и т.д. Примеры клавиш которые не создают символы, это клавиши модификаторы, такие как:Alt,Shift,Ctrl, orMeta.

Общая информация

Спецификация

DOM L3Устарело

Интерфейс

KeyboardEvent

Bubbles

Yes

Cancelable

Yes

Цель

Document, Element

Действие по умолчанию

Varies:keypress event; launch text composition system;blur andfocus events;DOMActivate event; other event

Свойства

СвойстваТипОписание
targetТолько для чтенияEventTargetЦель события (самая верхняя цель в дереве DOM).
typeТолько для чтенияDOMStringТип события.
bubblesТолько для чтенияBooleanWhether the event normally bubbles or not
cancelableТолько для чтенияBooleanОтменяется ли событие или нет
viewТолько для чтенияWindowProxydocument.defaultView (window of the document)
detailТолько для чтенияlong (float)0.
targetТолько для чтенияEventTarget (DOM element) Сосредоточенный элемент, обрабатывающий ключевое событие, корневой элемент, если не выделен подходящий элемент ввода.
charТолько для чтения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. Seekey names and char values for the detail.
Примечание: Если ключ используется в качестве макроса, который вставляет несколько символов, значением этого атрибута является вся строка, а не только первый символ.
keyТолько для чтения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 thechar property. Otherwise, it's one of the key value strings specified inKey values. If the key can't be identified, its value is the string "Unidentified". Seekey names and char values for more details. Read Only.

codeТолько для чтенияDOMString (string) Holds a string that identifies the physical key being pressed. The value is not affected by the current keyboard layout or modifier state, so a particular key will always return the same value.
charCodeТолько для чтенияUnsigned long (int) The Unicode reference number of the key; this attribute is used only by thekeypress event. For keys whosechar attribute contains multiple characters, this is the Unicode value of the first character in that attribute.
Warning: This attribute is deprecated; you should usechar instead, if available.
keyCodeТолько для чтения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; seeVirtual 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 usekey instead, if available.
whichТолько для чтенияUnsigned long (int) A system and implementation dependent numeric code identifying the unmodified value of the pressed key; this is usually the same askeyCode.
Warning: This attribute is deprecated; you should usekey instead, if available.
locationТолько для чтенияlong (float)The location of the key on the device.
repeatТолько для чтенияbooleantrue if a key has been depressed long enough to trigger key repetition, otherwisefalse.
localeТолько для чтенияstring The language code for the key event, if available; otherwise, the empty string.
ctrlKeyТолько для чтенияbooleantrue if the control key was down when the event was fired.false otherwise.
shiftKeyТолько для чтенияbooleantrue if the shift key was down when the event was fired.false otherwise.
altKeyТолько для чтенияbooleantrue if the alt key was down when the event was fired.false otherwise.
metaKeyТолько для чтенияbooleantrue if the meta key was down when the event was fired.false otherwise.

Примечания

Chrome не запускает событиеkeypress для известных сочетаний клавиш (reference). Какие сочетания клавиш известны, зависит от системы пользователя. Используйте событиеkeydown для реализации сочетаний клавиш.

Связанные события

Пример

html
<!doctype html><html>  <head>    <script>      "use strict";      document.addEventListener("keypress", (event) => {        const keyName = event.key;        alert("keypress event\n\n" + "key: " + keyName);      });    </script>  </head>  <body></body></html>

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp