Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt

Use this file to discover all available pages before exploring further.

The s&box Input class is a static API for reading player input inside your components. Rather than polling raw keys, you define named actions that map to keyboard keys, gamepad buttons, or VR controls — and query them with Input.Pressed, Input.Down, and Input.Released. This page covers action bindings, all three query methods, mouse and analog values, gamepad support, and VR.

Action bindings

Actions are named input events defined in your project’s Input Settings asset (a JSON file). Each action has a name, an optional keyboard binding, and an optional gamepad binding. The engine ships with a set of default common actions for games that do not define their own.

Default common actions

ActionDefault keyboardGamepadGroup
ForwardWMovement
BackwardSMovement
LeftAMovement
RightDMovement
JumpSpaceA ButtonMovement
RunShiftLeft Joystick ButtonMovement
DuckCtrlB ButtonMovement
Attack1Mouse1Right TriggerActions
Attack2Mouse2Left TriggerActions
ReloadRX ButtonActions
UseEY ButtonActions
Slot1Slot91–9D-PadInventory
SlotNextMouse5Right BumperInventory
SlotPrevMouse4Left BumperInventory
ViewCRight JoystickMisc
VoiceVMisc
FlashlightFD-Pad NorthMisc

Defining custom actions

Open your project’s Input Settings asset in the editor and add entries. Each InputAction has:
  • Name — alphanumeric identifier (no spaces). Used in code: Input.Down( "Sprint" ).
  • GroupName — category for the binding UI.
  • Title — optional friendly name shown in the UI.
  • KeyboardCode — key or mouse button string (e.g. "shift", "mouse1").
  • GamepadCode — a GamepadCode enum value.
// InputAction definition — usually set in the editor, shown here for reference
new InputAction( "Sprint", "shift", GamepadCode.LeftJoystickButton )
{
    GroupName = "Movement",
    Title = "Sprint"
};

Querying actions

All three query methods accept an action name string and return a bool. They must be called from a component’s OnUpdate (or another per-frame method).

Input.Down

Returns true while the action is held.
protected override void OnUpdate()
{
    if ( Input.Down( "Attack1" ) )
    {
        // Fires every frame the button is held
        FireWeapon();
    }
}

Input.Pressed

Returns true on the frame the action transitions from not-pressed to pressed (rising edge). Use this for single-trigger events like jumping or opening a menu.
protected override void OnUpdate()
{
    if ( Input.Pressed( "Jump" ) )
    {
        // Fires once per press, not while held
        Jump();
    }
}

Input.Released

Returns true on the frame the action transitions from pressed to not-pressed (falling edge).
protected override void OnUpdate()
{
    if ( Input.Released( "Attack1" ) )
    {
        StopFiring();
    }
}
All three methods return false on dedicated servers and when input is suppressed (e.g. a UI element has captured focus). You do not need to guard against server-side calls manually.

Suppressing input

If you want to prevent all input queries from returning true (for example, when a UI overlay is open), set Input.Suppressed = true for that frame. All Down, Pressed, Released, MouseDelta, MouseWheel, and AnalogLook calls return their zero/default values while suppressed.

Mouse input

MouseDelta

Input.MouseDelta is a Vector2 representing how far the mouse moved since the last frame, in screen pixels. The engine accumulates raw OS mouse movement and resets it each frame.
protected override void OnUpdate()
{
    var delta = Input.MouseDelta;
    // delta.x = horizontal, delta.y = vertical
}

MouseWheel

Input.MouseWheel is a Vector2 representing scroll input. The y component is the standard vertical scroll wheel.
protected override void OnUpdate()
{
    float scroll = Input.MouseWheel.y;
}

AnalogLook

Input.AnalogLook is an Angles value pre-scaled by Preferences.Sensitivity. It is automatically zeroed when the mouse cursor is visible. This is the preferred value to use for camera look logic:
protected override void OnUpdate()
{
    var look = Input.AnalogLook;
    // look.pitch = up/down, look.yaw = left/right
    EyeAngles += look;
}

AnalogMove

Input.AnalogMove is a Vector3 built from the Forward, Backward, Left, and Right actions. It combines keyboard WASD with controller left-stick input automatically.
protected override void OnUpdate()
{
    var wishDir = Input.AnalogMove;
    // wishDir.x = right/left, wishDir.y = up/down, wishDir.z = forward/backward
}

Gamepad support

The engine detects whether the last input event came from a gamepad and exposes this via Input.UsingController. You can branch your UI hints on this value.
if ( Input.UsingController )
{
    ShowGamepadPrompt( "A Button" );
}
else
{
    ShowKeyboardPrompt( Input.GetButtonOrigin( "Jump" ) );
}
Input.GetButtonOrigin( string actionName ) returns the human-readable key or button name for the given action, accounting for the current input device.
Use Input.GetButtonOrigin to display dynamic binding hints in your UI rather than hardcoding key names. The string adjusts automatically when the player switches between keyboard and gamepad.

Programmatic action control

You can set, clear, and release actions from code — useful for AI controllers or testing:
// Simulate pressing an action
Input.SetAction( "Jump", true );

// Clear a specific action (no longer pressed)
Input.Clear( "Attack1" );

// Clear all active actions
Input.ClearActions();

// Release all actions so they must be physically pressed again
Input.ReleaseActions();

// Release a single action
Input.ReleaseAction( "Jump" );

VR input

VR-specific input is available through Input.VR, which returns the VRInput.Current singleton. Use this for hand tracking, trigger values, and pose data on supported runtimes (SteamVR, OpenXR).
protected override void OnUpdate()
{
    var vr = Input.VR;
    // Access hand positions, orientations, and button state via vr.LeftHand / vr.RightHand
}
VR input is only meaningful when the game is running in a VR headset. On non-VR clients, Input.VR returns a default VRInput with all values at zero.

Motion sensor input

Controllers that expose a motion sensor (DualShock 4+, Switch controllers, Steam Controller, Steam Deck) provide orientation data via Input.MotionData:
var motion = Input.MotionData;

Scripting basics

Lifecycle methods and where to call input queries.

Action Graphs

Wire input nodes visually with the Action Graph editor.

Input API reference

Full static API for the Input class.

Character controller

Applying AnalogMove and AnalogLook to a character.

Build docs developers (and LLMs) love