Skip to content

inputManager

The InputManager class is responsible for handling raw DOM input events (keyboard and mouse) and emitting them as internal engine events used by other components, such as InputPacketCreator. It tracks the state of keys and mouse buttons and is integrated with the game's network lifecycle.

InputManager public

Bounded to game as game.inputManager. Extends EventEmitter, alias: game.inputManagerType

Properties

PropertyTypeDescription
mousePositionobjectThe current { x, y } coordinates of the mouse on the screen.
mouseDownbooleanWhether the primary mouse button is currently pressed.
mouseRightDownbooleanWhether the right mouse button is currently pressed.
keysDownobjectA map of key codes currently being held down.
enabledbooleanWhether input processing is currently active.

Getters & Setters

getEnabled()

ts
function getEnabled(): boolean

Returns whether the input manager is currently enabled.

setEnabled()

ts
function setEnabled(enabled: boolean): void

Enables or disables input processing. When disabled, it will also reset the mouseDown state and emit a mouseUp event if necessary. It also synchronizes the enabled state with InputPacketCreator.

Handlers & Emitters

MethodDescription
onKeyPress()Internal handler for keydown events. Updates keysDown and emits keyPress.
onKeyRelease()Internal handler for keyup events. Updates keysDown and emits keyRelease.
onMouseDown()Internal handler for mousedown events. Handles both primary and secondary (right-click) buttons, updates states, and emits corresponding events.
onMouseUp()Internal handler for mouseup events. Updates mouse states and emits corresponding events.
onMouseMoved()Internal handler for mousemove events. Updates mousePosition and emits either mouseMoved or mouseMovedWhileDown depending on the current mouseDown state.
Input Events

The InputManager emits the following events:

EventDataDescription
keyPressKeyboardEventFired when a key is pressed.
keyReleaseKeyboardEventFired when a key is released.
mouseDownMouseEventFired when the left mouse button is pressed.
mouseUpMouseEventFired when the left mouse button is released.
mouseRightDownMouseEventFired when the right mouse button is pressed.
mouseRightUpMouseEventFired when the right mouse button is released.
mouseMovedMouseEventFired when the mouse moves while no buttons are held.
mouseMovedWhileDownMouseEventFired when the mouse moves while the left button is held.