KeyboardEvent objects describe a user interaction with the keyboard; each event describes a single interaction between the user and a key (or combination of a key with modifier keys) on the keyboard.

interface KeyboardEvent {
    altKey: boolean;
    AT_TARGET: number;
    bubbles: boolean;
    BUBBLING_PHASE: number;
    cancelable: boolean;
    cancelBubble: boolean;
    CAPTURING_PHASE: number;
    charCode: number;
    code: string;
    composed: boolean;
    ctrlKey: boolean;
    currentTarget: null | EventTarget;
    defaultPrevented: boolean;
    detail: number;
    DOM_KEY_LOCATION_LEFT: number;
    DOM_KEY_LOCATION_NUMPAD: number;
    DOM_KEY_LOCATION_RIGHT: number;
    DOM_KEY_LOCATION_STANDARD: number;
    eventPhase: number;
    isComposing: boolean;
    isTrusted: boolean;
    key: string;
    keyCode: number;
    location: number;
    metaKey: boolean;
    NONE: number;
    repeat: boolean;
    returnValue: boolean;
    shiftKey: boolean;
    srcElement: null | EventTarget;
    target: null | EventTarget;
    timeStamp: number;
    type: string;
    view: null | Window;
    which: number;
    composedPath(): EventTarget[];
    getModifierState(keyArg: string): boolean;
    initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void;
    initKeyboardEvent(typeArg: string, bubblesArg?: boolean, cancelableArg?: boolean, viewArg?: null | Window, keyArg?: string, locationArg?: number, ctrlKey?: boolean, altKey?: boolean, shiftKey?: boolean, metaKey?: boolean): void;
    initUIEvent(typeArg: string, bubblesArg?: boolean, cancelableArg?: boolean, viewArg?: null | Window, detailArg?: number): void;
    preventDefault(): void;
    stopImmediatePropagation(): void;
    stopPropagation(): void;
}

层级 (查看完整内容)

属性

altKey: boolean
AT_TARGET: number
bubbles: boolean

Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise.

BUBBLING_PHASE: number
cancelable: boolean

Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method.

cancelBubble: boolean
CAPTURING_PHASE: number
charCode: number
code: string
composed: boolean

Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise.

ctrlKey: boolean
currentTarget: null | EventTarget

Returns the object whose event listener's callback is currently being invoked.

defaultPrevented: boolean

Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise.

detail: number
DOM_KEY_LOCATION_LEFT: number
DOM_KEY_LOCATION_NUMPAD: number
DOM_KEY_LOCATION_RIGHT: number
DOM_KEY_LOCATION_STANDARD: number
eventPhase: number

Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE.

isComposing: boolean
isTrusted: boolean

Returns true if event was dispatched by the user agent, and false otherwise.

key: string
keyCode: number
location: number
metaKey: boolean
NONE: number
repeat: boolean
returnValue: boolean
shiftKey: boolean
srcElement: null | EventTarget
target: null | EventTarget

Returns the object to which event is dispatched (its target).

timeStamp: number

Returns the event's timestamp as the number of milliseconds measured relative to the time origin.

type: string

Returns the type of event, e.g. "click", "hashchange", or "submit".

view: null | Window
which: number

方法

  • Returns the invocation target objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget.

    返回 EventTarget[]

  • 参数

    • keyArg: string

    返回 boolean

  • 参数

    • type: string
    • 可选bubbles: boolean
    • 可选cancelable: boolean

    返回 void

  • 参数

    • typeArg: string
    • 可选bubblesArg: boolean
    • 可选cancelableArg: boolean
    • 可选viewArg: null | Window
    • 可选keyArg: string
    • 可选locationArg: number
    • 可选ctrlKey: boolean
    • 可选altKey: boolean
    • 可选shiftKey: boolean
    • 可选metaKey: boolean

    返回 void

  • 参数

    • typeArg: string
    • 可选bubblesArg: boolean
    • 可选cancelableArg: boolean
    • 可选viewArg: null | Window
    • 可选detailArg: number

    返回 void

  • If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled.

    返回 void

  • Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects.

    返回 void

  • When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object.

    返回 void