Input

Static entry point for reading keyboard and mouse state from gameplay code. public override void OnUpdate(float deltaTime) { if (Input.IsKeyDown(Key.W)) Node.Transform = Node.Transform.Translate(forward * speed * deltaTime); }

Remarks

Resolves an IInputSource from RuntimeServices on each call, so the same component works unchanged in the standalone runtime and in the Studio's play mode. When no source is registered — for example while the editor is merely previewing a scene — every query returns a neutral value instead of throwing.

Example

` public override void OnUpdate(float deltaTime) { if (Input.IsKeyDown(Key.W)) Node.Transform = Node.Transform.Translate(forward * speed * deltaTime); } `

Properties

Source

(IInputSource?): Gets the active input source, or null when input is not routed.

MousePosition

(Vector2): Gets the pointer position in viewport pixels, with the origin at the top-left.

MouseDelta

(Vector2): Gets the pointer movement, in pixels, accumulated during the current frame.

MouseScrollDelta

(float): Gets the scroll-wheel movement, in notches, accumulated during the current frame.

ConnectedGamepads

(IReadOnlyList): Gets the player slots that currently have a gamepad attached.

Public Methods

IsKeyDown

public static bool IsKeyDown(Key key)

Returns true while key is held down.

Parameters:

  • key (Key)

Returns: bool

WasKeyPressed

public static bool WasKeyPressed(Key key)

Returns true only during the frame in which key went down.

Parameters:

  • key (Key)

Returns: bool

WasKeyReleased

public static bool WasKeyReleased(Key key)

Returns true only during the frame in which key went up.

Parameters:

  • key (Key)

Returns: bool

IsMouseButtonDown

public static bool IsMouseButtonDown(MouseButton button)

Returns true while button is held down.

Parameters:

  • button (MouseButton)

Returns: bool

WasMouseButtonPressed

public static bool WasMouseButtonPressed(MouseButton button)

Returns true only during the frame in which button went down.

Parameters:

  • button (MouseButton)

Returns: bool

WasMouseButtonReleased

public static bool WasMouseButtonReleased(MouseButton button)

Returns true only during the frame in which button went up.

Parameters:

  • button (MouseButton)

Returns: bool

IsGamepadButtonDown

public static bool IsGamepadButtonDown(GamepadButton button, int playerIndex = -1)

Returns true while a gamepad button is held.

Parameters:

  • button (GamepadButton): The button to test.
  • playerIndex (int): The player slot, or −1 for any attached gamepad. (Default: -1)

Returns: bool

WasGamepadButtonPressed

public static bool WasGamepadButtonPressed(GamepadButton button, int playerIndex = -1)

Returns true only during the frame in which a gamepad button went down.

Parameters:

  • button (GamepadButton): The button to test.
  • playerIndex (int): The player slot, or −1 for any attached gamepad. (Default: -1)

Returns: bool

WasGamepadButtonReleased

public static bool WasGamepadButtonReleased(GamepadButton button, int playerIndex = -1)

Returns true only during the frame in which a gamepad button went up.

Parameters:

  • button (GamepadButton): The button to test.
  • playerIndex (int): The player slot, or −1 for any attached gamepad. (Default: -1)

Returns: bool

GetGamepadAxis

public static float GetGamepadAxis(GamepadAxis axis, int playerIndex = -1)

Reads a gamepad axis: −1 to 1 for a stick, 0 to 1 for a trigger.

Parameters:

  • axis (GamepadAxis): The axis to read.
  • playerIndex (int): The player slot, or −1 for the attached gamepad furthest from rest. (Default: -1)

Returns: float

Read

public static float Read(InputControl control, int playerIndex = -1)

Reads one physical control through whatever it is: a press for a button, the current value for an axis. What an InputAction resolves each of its bindings with.

Parameters:

  • control (InputControl): The control to read.
  • playerIndex (int): The player slot for a gamepad control, or −1 for any. (Default: -1)

Returns: float

  • 1 or 0 for a button, the axis value otherwise.