Skip to content

@relu-interactives/spatial-ecs


@relu-interactives/spatial-ecs / index / InputSystem

Class: InputSystem ​

Defined in: systems/InputSystem.ts:87

Implements ​

Constructors ​

Constructor ​

ts
new InputSystem(options?): InputSystem;

Defined in: systems/InputSystem.ts:317

Parameters ​

ParameterType
optionsInputSystemOptions

Returns ​

InputSystem

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
runsWhilePausedreadonlytruetrueonPausedUpdate reads input the same way onUpdate does.systems/InputSystem.ts:89
actionsreadonlyInputActionsundefinedNamed actions over every device. Read through getAction, getAxis and friends.systems/InputSystem.ts:115
touchreadonlyTouchControls | nullundefinedThe on-screen controls, or null when this game has none.systems/InputSystem.ts:117

Methods ​

setPointerLockElement() ​

ts
setPointerLockElement(element): void;

Defined in: systems/InputSystem.ts:344

Parameters ​

ParameterType
elementHTMLElement | null

Returns ​

void


lockMousePointer() ​

ts
lockMousePointer(): boolean;

Defined in: systems/InputSystem.ts:351

Returns ​

boolean


unlockMousePointer() ​

ts
unlockMousePointer(): boolean;

Defined in: systems/InputSystem.ts:378

Returns ​

boolean


isMousePointerLocked() ​

ts
isMousePointerLocked(): boolean;

Defined in: systems/InputSystem.ts:394

Returns ​

boolean


getKey() ​

ts
getKey(key): boolean;

Defined in: systems/InputSystem.ts:411

Parameters ​

ParameterType
keystring

Returns ​

boolean


getKeyDown() ​

ts
getKeyDown(key): boolean;

Defined in: systems/InputSystem.ts:415

Parameters ​

ParameterType
keystring

Returns ​

boolean


getKeyUp() ​

ts
getKeyUp(key): boolean;

Defined in: systems/InputSystem.ts:419

Parameters ​

ParameterType
keystring

Returns ​

boolean


consumePressed() ​

ts
consumePressed(key): boolean;

Defined in: systems/InputSystem.ts:423

Parameters ​

ParameterType
keystring

Returns ​

boolean


getMouse() ​

ts
getMouse(button): boolean;

Defined in: systems/InputSystem.ts:433

Parameters ​

ParameterType
buttonstring | number

Returns ​

boolean


getMouseDown() ​

ts
getMouseDown(button): boolean;

Defined in: systems/InputSystem.ts:442

Parameters ​

ParameterType
buttonstring | number

Returns ​

boolean


getMouseUp() ​

ts
getMouseUp(button): boolean;

Defined in: systems/InputSystem.ts:451

Parameters ​

ParameterType
buttonstring | number

Returns ​

boolean


getScrollClick() ​

ts
getScrollClick(): boolean;

Defined in: systems/InputSystem.ts:460

Returns ​

boolean


getScrollClickDown() ​

ts
getScrollClickDown(): boolean;

Defined in: systems/InputSystem.ts:464

Returns ​

boolean


getScrollClickUp() ​

ts
getScrollClickUp(): boolean;

Defined in: systems/InputSystem.ts:468

Returns ​

boolean


getScrollDelta() ​

ts
getScrollDelta(): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:472

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:472
ynumbersystems/InputSystem.ts:472

consumeScrollDelta() ​

ts
consumeScrollDelta(): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:479

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:479
ynumbersystems/InputSystem.ts:479

getMousePosition() ​

ts
getMousePosition(): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:486

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:486
ynumbersystems/InputSystem.ts:486

getMouseDelta() ​

ts
getMouseDelta(): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:493

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:493
ynumbersystems/InputSystem.ts:493

consumeMouseDelta() ​

ts
consumeMouseDelta(): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:500

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:500
ynumbersystems/InputSystem.ts:500

update() ​

ts
update(world, deltaTime): void;

Defined in: systems/InputSystem.ts:507

Parameters ​

ParameterType
worldWorld
deltaTimenumber

Returns ​

void

Implementation of ​

EcsSystem.update


onWorldPause() ​

ts
onWorldPause(): void;

Defined in: systems/InputSystem.ts:560

The press that opens a menu must not reach the menu in the same breath, or Escape opens and closes it at once.

Returns ​

void

Implementation of ​

EcsSystem.onWorldPause


onWorldResume() ​

ts
onWorldResume(): void;

Defined in: systems/InputSystem.ts:570

A click on a DOM Resume button leaves its release waiting for the next frame, which would be the first one of gameplay. Held keys stay held.

Returns ​

void

Implementation of ​

EcsSystem.onWorldResume


dispose() ​

ts
dispose(): void;

Defined in: systems/InputSystem.ts:595

Returns ​

void

Implementation of ​

EcsSystem.dispose


getAction() ​

ts
getAction(name): boolean;

Defined in: systems/InputSystem.ts:635

Held this frame: getAction("jump").

Parameters ​

ParameterType
namestring

Returns ​

boolean


getActionDown() ​

ts
getActionDown(name): boolean;

Defined in: systems/InputSystem.ts:640

Pressed this frame.

Parameters ​

ParameterType
namestring

Returns ​

boolean


getActionUp() ​

ts
getActionUp(name): boolean;

Defined in: systems/InputSystem.ts:645

Released this frame.

Parameters ​

ParameterType
namestring

Returns ​

boolean


getActionValue() ​

ts
getActionValue(name): number;

Defined in: systems/InputSystem.ts:650

0..1, e.g. how far a trigger is pulled.

Parameters ​

ParameterType
namestring

Returns ​

number


getAxis() ​

ts
getAxis(name): {
  x: number;
  y: number;
};

Defined in: systems/InputSystem.ts:655

move: -1..1, y forward. look: pixels this frame, y down, like the mouse.

Parameters ​

ParameterType
namestring

Returns ​

ts
{
  x: number;
  y: number;
}
NameTypeDefined in
xnumbersystems/InputSystem.ts:655
ynumbersystems/InputSystem.ts:655

getNavigation() ​

ts
getNavigation(): NavigationDirection | null;

Defined in: systems/InputSystem.ts:660

A menu step with hold-to-repeat, from arrows, WASD, the D-pad or a stick.

Returns ​

NavigationDirection | null


getLastDevice() ​

ts
getLastDevice(): InputDevice;

Defined in: systems/InputSystem.ts:665

The device the player used last: keyboard, mouse, gamepad or touch.

Returns ​

InputDevice


getGamepadFamily() ​

ts
getGamepadFamily(): GamepadFamily | null;

Defined in: systems/InputSystem.ts:670

The family of the pad in use, or of the first one connected.

Returns ​

GamepadFamily | null


getGamepads() ​

ts
getGamepads(): GamepadSnapshot[];

Defined in: systems/InputSystem.ts:675

Pads connected now, read this frame.

Returns ​

GamepadSnapshot[]


onDeviceChange() ​

ts
onDeviceChange(listener): () => void;

Defined in: systems/InputSystem.ts:680

Called when the player switches device. Returns an unsubscribe.

Parameters ​

ParameterType
listenerDeviceListener

Returns ​

() => void


onGamepadChange() ​

ts
onGamepadChange(listener): () => void;

Defined in: systems/InputSystem.ts:686

Called when a pad is connected or disconnected. Returns an unsubscribe.

Parameters ​

ParameterType
listenerGamepadListener

Returns ​

() => void


getPrompt() ​

ts
getPrompt(action, device?): InputPrompt;

Defined in: systems/InputSystem.ts:695

How an action reads for the device in use (or the one given): what a prompt like "Press A to jump" needs.

Parameters ​

ParameterType
actionstring
deviceInputDevice

Returns ​

InputPrompt


getGamepadButtonLabel() ​

ts
getGamepadButtonLabel(button, family?): string;

Defined in: systems/InputSystem.ts:717

A button's name on a pad family: getGamepadButtonLabel("south") → "A" or "Cross".

Parameters ​

ParameterType
buttonstring | number
familyGamepadFamily

Returns ​

string


getActionBindings() ​

ts
getActionBindings(action): string[];

Defined in: systems/InputSystem.ts:722

An action's bindings as they are now, rebinds included.

Parameters ​

ParameterType
actionstring

Returns ​

string[]


rebind() ​

ts
rebind(action, bindings): boolean;

Defined in: systems/InputSystem.ts:727

Change an action's bindings and save them for this player.

Parameters ​

ParameterType
actionstring
bindingsstring[]

Returns ​

boolean


resetBindings() ​

ts
resetBindings(action?): void;

Defined in: systems/InputSystem.ts:734

Back to the shipped bindings (one action or all) and save.

Parameters ​

ParameterType
action?string

Returns ​

void


defineActions() ​

ts
defineActions(actions): void;

Defined in: systems/InputSystem.ts:740

Add actions a game needs beyond the defaults, e.g. { dash: { kind: "button", bindings: ["key:KeyQ", "pad:rb"] } }.

Parameters ​

ParameterType
actionsInputActionMap

Returns ​

void


captureBinding() ​

ts
captureBinding(options?): Promise<string | null>;

Defined in: systems/InputSystem.ts:751

Wait for the next key, mouse button or pad button and return it as a binding (key:KeyF, pad:west). Escape or the timeout gives null. While it waits, no action fires.

Parameters ​

ParameterType
options{ devices?: InputDevice[]; timeoutMs?: number; }
options.devices?InputDevice[]
options.timeoutMs?number

Returns ​

Promise<string | null>


rumble() ​

ts
rumble(
   strong?, 
   weak?, 
   ms?): void;

Defined in: systems/InputSystem.ts:766

Rumble every pad (and vibrate a phone) for ms, unless the player turned vibration off.

Parameters ​

ParameterTypeDefault value
strongnumber0.6
weaknumber0.4
msnumber120

Returns ​

void