Skip to content

Documentation / scene / InputManager

Class: InputManager

Defined in: libs/scene/src/app/inputmgr.ts:48

Input manager

Centralizes DOM input event handling for the engine:

  • Subscribes to pointer/keyboard/drag/wheel/composition events on the target canvas element.
  • Normalizes click and double-click detection using distance/time tolerances.
  • Supports a middleware chain (use) to intercept and optionally consume events before they are dispatched to the Application's observable event map.
  • Manages pointer capture for mouse interactions to ensure consistent up/move delivery.

Lifecycle:

  • Call start() to attach all event listeners; stop() to remove them.

Constructors

Constructor

new InputManager(app): InputManager

Defined in: libs/scene/src/app/inputmgr.ts:74

Creates an instance of InputManager bound to the given application/canvas.

Parameters

app

Application

The owning Application instance.

Returns

InputManager

Methods

use()

use(handler, ctx?): InputManager

Defined in: libs/scene/src/app/inputmgr.ts:170

Register a middleware (interceptor) for input events.

Order matters: middlewares are invoked in the order they were added until one returns true. If a middleware returns true, the event is considered handled and will not be dispatched to the Application's observers.

Parameters

handler

InputEventHandler

Middleware function to add.

ctx?

unknown

this object for handler

Returns

InputManager

The InputManager instance for chaining.


useFirst()

useFirst(handler, ctx?): InputManager

Defined in: libs/scene/src/app/inputmgr.ts:183

Register a middleware (interceptor) for input events at the first order.

Parameters

handler

InputEventHandler

Middleware function to add.

ctx?

unknown

this object for handler

Returns

InputManager

The InputManager instance for chaining.


unuse()

unuse(handler, ctx?): InputManager

Defined in: libs/scene/src/app/inputmgr.ts:203

Unregister a previously registered middleware (interceptor) for input events.

Removes the first middleware that matches both the given handler and ctx. If no matching middleware is found, this method is a no-op.

Note: This only removes the specific pair of (handler, ctx) previously added via use. If the same handler was registered multiple times with different contexts, only the first exact match will be removed.

Parameters

handler

InputEventHandler

Middleware function to remove.

ctx?

unknown

this object that was associated with the handler when it was added.

Returns

InputManager

The InputManager instance for chaining.


enableSystemContextMenu()

enableSystemContextMenu(enable): void

Defined in: libs/scene/src/app/inputmgr.ts:210

Parameters

enable

boolean

Returns

void


log()

static log(ev, type?): boolean

Defined in: libs/scene/src/app/inputmgr.ts:222

Utility middleware that logs the event type to the console.

Can be used with use(InputManager.log) for quick diagnostics.

Parameters

ev

Event

The DOM event being logged.

type?

string

Optional explicit event type; falls back to ev.type.

Returns

boolean

Always false (does not consume the event).

Released under the MIT License.