playcanvas
Version:
Open-source WebGL/WebGPU 3D engine for the web
48 lines (47 loc) • 1.49 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
class KeyboardEvent {
/**
* Create a new KeyboardEvent.
*
* @param {Keyboard} keyboard - The keyboard object which is firing the event.
* @param {globalThis.KeyboardEvent} event - The original browser event that was fired.
* @example
* 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);
*/
constructor(keyboard, event) {
/**
* The keyCode of the key that has changed. See the KEY_* constants.
*
* @type {number|null}
*/
__publicField(this, "key", null);
/**
* The element that fired the keyboard event.
*
* @type {Element|null}
*/
__publicField(this, "element", null);
/**
* The original browser event which was fired.
*
* @type {globalThis.KeyboardEvent|null}
*/
__publicField(this, "event", null);
if (event) {
this.key = event.keyCode;
this.element = event.target;
this.event = event;
}
}
}
export {
KeyboardEvent
};