目录

HTML DOM KeyboardEvent

❮ DOM 事件 ❮ 事件对象


键盘事件对象

KeyboardEvent 对象处理用户按下键盘上的按键时发生的事件。

键盘事件

Event Occurs When
onkeydown A user presses a key
onkeypress A user presses a key
onkeyup A user releases a key

键盘事件属性

Property Returns
altKey If the ALT key was pressed
charCode Deprecated (Avoid using it)
code The code of the key that triggered the event
ctrlKey If the CTRL key was pressed
isComposing If the state of the event is composing or not
key The value of the key that triggered the event
keyCode Deprecated (Avoid using it)
location The location of a key on the keyboard or device
metaKey If the META key was pressed
repeat If a key is being hold down repeatedly, or not
shiftKey If the SHIFT key was pressed
which Deprecated (Avoid using it)

键盘事件方法

Method Description
getModifierState() Returns true if the specified key is activated

继承的属性和方法

KeyboardEvent 继承了以下所有属性和方法:

Ui事件

事件对象


❮ DOM 事件 ❮ 事件对象