API Reference

Class List

KeyboardEvent

The KeyboardEvent is passed into all event callbacks from the Keyboard. It corresponds to a key press or release.

const onKeyDown = function (e) {
    if (e.key === pc.KEY_SPACE) {
        // space key pressed
    }
    e.event.preventDefault(); // Use original browser event to prevent browser action.
};
app.keyboard.on("keydown", onKeyDown, this);

Summary

Properties

element

The element that fired the keyboard event.

event

The original browser event which was fired.

key

The keyCode of the key that has changed.

Details

Constructor

KeyboardEvent(keyboard, event)

Create a new KeyboardEvent.

const onKeyDown = function (e) {
    if (e.key === pc.KEY_SPACE) {
        // space key pressed
    }
    e.event.preventDefault(); // Use original browser event to prevent browser action.
};
app.keyboard.on("keydown", onKeyDown, this);

Parameters

keyboardKeyboard

The keyboard object which is firing the event.

eventglobalThis.KeyboardEvent

The original browser event that was fired.

Properties

Elementelement

The element that fired the keyboard event.

globalThis.KeyboardEventevent

The original browser event which was fired.

numberkey

The keyCode of the key that has changed. See the KEY_* constants.