Skip to content
bg2 engine

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.


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.


Creates a new keyboard event instance.

  • key: The key value associated with the event (typically event.key)
  • event: The original native keyboard event

The key value associated with the event.

This typically corresponds to the value provided by the browser (event.key).


Reference to the original native keyboard event.

This allows access to additional properties not exposed directly by the engine wrapper.


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.


Checks whether a native keyboard event corresponds to a special key.

  • event: Native keyboard event
  • true if the event represents a special key
  • false otherwise

  • This class is used in AppController input callbacks such as keyDown and keyUp.
  • Use key for standard input handling.
  • Use isSpecialKey to detect control and navigation keys.
  • Access event when low-level browser-specific data is required.

keyDown(evt: Bg2KeyboardEvent) {
if (evt.isSpecialKey) {
console.log("Special key pressed:", evt.key);
}
else {
console.log("Character key pressed:", evt.key);
}
}