Bg2KeyboardEvent
The Bg2KeyboardEvent class represents keyboard input events in the bg2 engine TypeScript API. It extends EventBase, inheriting support for event propagation control.
This class wraps the native browser keyboard event and provides a normalized interface for handling keyboard input within the engine.
SpecialKey Enum
Section titled “SpecialKey Enum”The SpecialKey enum defines a set of recognized non-character keys.
export enum SpecialKey { BACKSPACE = "Backspace", TAB = "Tab", ENTER = "Enter", SHIFT = "Shift", SHIFT_LEFT = "ShiftLeft", SHIFT_RIGHT = "ShiftRight", CTRL = "Control", CTRL_LEFT = "ControlLeft", CTRL_RIGHT = "ControlRight", ALT = "Alt", ALT_LEFT = "AltLeft", ALT_RIGHT = "AltRight", PAUSE = "Pause", CAPS_LOCK = "CapsLock", ESCAPE = "Escape", PAGE_UP = "PageUp", PAGEDOWN = "PageDown", END = "End", HOME = "Home", LEFT_ARROW = "ArrowLeft", UP_ARROW = "ArrowUp", RIGHT_ARROW = "ArrowRight", DOWN_ARROW = "ArrowDown", INSERT = "Insert", DELETE = "Delete", SPACE = "Space"}This enum is used to identify keys that do not correspond to standard character input.
Constructor
Section titled “Constructor”constructor(key: string, event: any)
Section titled “constructor(key: string, event: any)”Creates a new keyboard event instance.
Parameters
Section titled “Parameters”key: The key value associated with the event (typicallyevent.key)event: The original native keyboard event
Properties
Section titled “Properties”key: string
Section titled “key: string”The key value associated with the event.
This typically corresponds to the value provided by the browser (event.key).
event: any
Section titled “event: any”Reference to the original native keyboard event.
This allows access to additional properties not exposed directly by the engine wrapper.
isSpecialKey: boolean
Section titled “isSpecialKey: boolean”Indicates whether the key corresponds to a value defined in the SpecialKey enum.
Returns true if the key is recognized as a special key, false otherwise.
Static Methods
Section titled “Static Methods”static IsSpecialKey(event: any): boolean
Section titled “static IsSpecialKey(event: any): boolean”Checks whether a native keyboard event corresponds to a special key.
Parameters
Section titled “Parameters”event: Native keyboard event
Returns
Section titled “Returns”trueif the event represents a special keyfalseotherwise
Usage Notes
Section titled “Usage Notes”- This class is used in
AppControllerinput callbacks such askeyDownandkeyUp. - Use
keyfor standard input handling. - Use
isSpecialKeyto detect control and navigation keys. - Access
eventwhen low-level browser-specific data is required.
Example
Section titled “Example”keyDown(evt: Bg2KeyboardEvent) { if (evt.isSpecialKey) { console.log("Special key pressed:", evt.key); } else { console.log("Character key pressed:", evt.key); }}