Input

Turian offers two layers, usable side by side:

  • Input — ask a device directly: is W held?
  • InputActions — ask about a game action: is Jump pressed? Which keys and buttons drive each action lives in an Input Actions asset that designers edit and players can rebind.

Both work unchanged in Studio's Play Mode and in exported games. Key codes (Key.W, MouseButton.Left) come from Silk.NET; new projects import that namespace in their Globals.cs.

Device queries

public class Mover : Component
{
    public float speed = 4f;

    public override void OnUpdate(float deltaTime)
    {
        var move = Vector3.Zero;
        if (Input.IsKeyDown(Key.W)) move.Z += 1;
        if (Input.IsKeyDown(Key.S)) move.Z -= 1;
        if (Input.WasKeyPressed(Key.Space)) Log.Logger.LogInformation("Jump!");

        Node!.Transform.Position += move * speed * deltaTime;
    }
}
Query Returns
Input.IsKeyDown(key) / WasKeyPressed(key) / WasKeyReleased(key) held / went down this frame / went up this frame
Input.IsMouseButtonDown(button), WasMouseButtonPressed, WasMouseButtonReleased the same for mouse buttons
Input.MousePosition, Input.MouseDelta, Input.MouseScrollDelta pointer position, movement this frame, wheel
Input.ConnectedGamepads player indices of attached gamepads
Input.IsGamepadButtonDown(button, player), WasGamepadButtonPressed, WasGamepadButtonReleased gamepad buttons; player −1 means any
Input.GetGamepadAxis(axis, player) sticks and triggers, −1 to 1

Gamepad buttons use positional names — South, East, West, North (A/B/X/Y on an Xbox pad), shoulders, Back, Start, stick clicks and the D-pad; axes are LeftStickX/Y, RightStickX/Y, LeftTrigger and RightTrigger.

Action maps

1. Create the asset

In the Assets panel, right-click → New → Input → Input Actions. Select it to edit it in the Inspector.

2. Define maps and actions

An asset holds maps (for example Gameplay and Menu), and each map holds actions:

Action type Read with Example
Button IsPressed, WasPressed, WasReleased Jump, Fire, Pause
Axis ReadAxis() (−1 to 1) Throttle
Vector2 ReadVector() Move, Look

Each action has a list of bindings. A binding names a control with a path — Keyboard/W, Mouse/Left, Mouse/DeltaX, Gamepad/South, Gamepad/LeftStickX — and a value: what a button contributes when held, or what an axis reading is multiplied by. A WASD Move action therefore has four bindings: W with (0, 1), S with (0, −1), A with (−1, 0) and D with (1, 0); a stick binding with (−1, 0) inverts it.

3. Make it the project's actions

Open the project's Input Settings (in Assets/Settings/) and drop your asset onto Actions. The game loads those maps at startup.

Reading actions

public class PlayerController : Component
{
    public float speed = 5f;

    public override void OnUpdate(float deltaTime)
    {
        var move = InputActions.ReadVector("Gameplay/Move");
        Node!.Transform.Position += new Vector3(move.X, 0, move.Y) * speed * deltaTime;

        if (InputActions.WasPressed("Jump")) Jump();
    }

    void Jump() { /* … */ }
}

Name an action as Map/Action, or by its bare name to search every map. When no actions asset is configured, every query returns a neutral value instead of throwing.

Call Effect
InputActions.IsPressed(path) / WasPressed / WasReleased button state and edges
InputActions.ReadAxis(path) / ReadVector(path) analog values
InputActions.Find(path) the InputAction, with Started, Performed and Canceled events
InputActions.SetMapEnabled("Gameplay", false) stop a whole map — while a menu is open, for example

Runtime rebinding

InputActionService lets a settings menu rebind controls:

var service = InputActions.Service!;
var jump = service.Find("Gameplay/Jump")!;

var rebind = service.StartRebind(jump, bindingIndex: 0);   // listens for the next key or button
// … each frame, check rebind.IsComplete / rebind.WasCancelled; service.CancelRebind() aborts.

An exported game restores the player's rebinds at startup from inputbindings.json in the user's application data folder, under the game's product name; InputBindingStore.Save(service, InputBindingStore.DefaultPath(product)) writes them.

In Studio

Play Mode routes the keyboard and mouse to the game while the Game view has focus: click inside it to play, press Escape to give the keyboard back to Studio.


← All docs Edit this page