InputController

@three-blocks/proInputKeyboard
new InputController(options : Object)

Create a new InputController.

Constructor Parameters
optionsoptionalObject
Configuration options
Default is {}.
  • elementoptionalEventTarget
    Element to attach events to (virtualElement for offscreen, window for main thread)
  • dispatcheroptionalObject
    Dispatcher with .on()/.off() for forwarded events (alternative to element)
  • enableEditorKeysoptionalboolean
    Enable editor/debug keys (., ,, /)
    Default is true.
  • enableCameraToggleoptionalboolean
    Enable camera mode toggle (V key)
    Default is true.
  • keyConfigoptionalArray
    Custom key configuration (defaults to standard game controls)
  • onToggleCameraoptionalfunction
    Callback when camera toggle key is pressed
  • onTogglePauseoptionalfunction
    Callback when pause key is pressed
  • onToggleEditoroptionalfunction
    Callback when editor toggle key is pressed
  • onToggleOrbitoptionalfunction
    Callback when orbit toggle key is pressed

Methods

releaseAllKeys#

releaseAllKeys()

Release all pressed keys and reset input state.

isPressed#

isPressed(action : string) : boolean

Check if a specific action key is currently pressed.

Parameters
actionstring
Action name (forward, backward, left, right, jump)
Returns
boolean — Whether the action key is pressed

getMovementState#

getMovementState() : Object

Get current movement input state.

Returns
Object

getInput#

getInput() : Object

Get current input state formatted for PhysicsController.applyInput().

Jump uses edge detection for bhop support - jumpPressed is only true on the frame the key goes down, not while held. This prevents multiple physics steps from seeing the same jump input.

Returns
Object — Input state object

getMovementInput#

getMovementInput() : Object

Get current movement input as a normalized vector.

Returns
Object — Normalized input vector

setInputState#

setInputState(state : Object)

Set input state programmatically (for gamepad or touch controls).

Parameters
stateObject
Input state to set
  • forwardoptionalboolean
    Forward state
  • backwardoptionalboolean
    Backward state
  • leftoptionalboolean
    Left state
  • rightoptionalboolean
    Right state
  • jumpoptionalboolean
    Jump state

setAnalogInput#

setAnalogInput(x : number, y : number, jump : boolean, deadzone : number)

Set input from analog values (for gamepad sticks).

Parameters
xnumber
X axis value (-1 to 1)
ynumber
Y axis value (-1 to 1)
jumpoptionalboolean
Jump button state
Default is false.
deadzoneoptionalnumber
Deadzone threshold
Default is 0.2.

dispose#

dispose()

Dispose and clean up all event listeners. Call this when the controller is no longer needed.