Skip to main content
Use the Input class inside any component to check which buttons are pressed, read analog stick values, and respond to player actions. Input actions are named strings (like "jump") that map to keys you configure in Project Settings, so players can rebind them without any code changes.

Reading button state

Call these methods inside OnUpdate() to react to input each frame:
public sealed class MyPlayerComponent : Component
{
    protected override void OnUpdate()
    {
        if ( Input.Down( "jump" ) )
        {
            WorldPosition += Vector3.Forward * Time.Delta;
        }
    }
}
The three button state methods are:
MethodWhen it returns true
Input.Down( "action" )The button is held down this frame
Input.Pressed( "action" )The button was just pressed this frame
Input.Released( "action" )The button was just released this frame
Action names are case-insensitive.

Analog inputs

Use these properties to read directional and look input, which automatically maps to both keyboard/mouse and gamepad sticks:
Vector3 move = Input.AnalogMove;   // WASD or left stick — movement direction
Angles look  = Input.AnalogLook;   // Mouse delta or right stick — look direction

Custom key bindings

Define your game’s input actions in Project Settings → Input. Each action maps a name like "jump" to one or more keys. Players can rebind actions through the standard s&box settings menu.
Input action names are case-insensitive, so "Jump" and "jump" refer to the same action.

Escape key

By default, s&box shows its pause menu when the player presses Escape. You can intercept it and handle it yourself:
protected override void OnUpdate()
{
    if ( Input.EscapePressed )
    {
        Input.EscapePressed = false;
        // Open your own pause menu here
    }
}
If you consume Input.EscapePressed, you take full responsibility for giving players access to settings and the ability to exit your game.

Controller input

Detecting controller use

bool usingController = Input.UsingController;
int connectedControllers = Input.ControllerCount;

Reading analog axes directly

float moveX     = Input.GetAnalog( InputAnalog.LeftStickX );
float aimAmount = Input.GetAnalog( InputAnalog.LeftTrigger );

Haptics and rumble

Trigger rumble with precise motor values:
float leftMotor    = 0.5f;  // 50% intensity
float rightMotor   = 0.7f;  // 70% intensity
float leftTrigger  = 0.2f;  // 20% intensity
float rightTrigger = 0f;    // No vibration
int   duration     = 1000;  // Milliseconds

Input.TriggerHaptics( leftMotor, rightMotor, leftTrigger, rightTrigger, duration );
Or use a preset effect with optional scaling:
float lengthScale    = 1.2f; // 1.2x longer
float frequencyScale = 2f;   // 2x frequency
float amplitudeScale = 0.5f; // Half intensity

Input.TriggerHaptics( HapticEffect.HardImpact, lengthScale, frequencyScale, amplitudeScale );
Stop all haptics immediately with Input.StopAllHaptics().

Motion controls

If the controller has a gyroscope or accelerometer:
InputMotionData motionData = Input.MotionData;
if ( motionData is not null )
{
    Vector3 acceleration    = motionData.Acceleration;    // Accelerometer
    Vector3 angularVelocity = motionData.AngularVelocity; // Gyroscope
}

Local multiplayer

Scope input queries to a specific controller index to support multiple local players:
int playerIndex = 0;

using ( Input.PlayerScope( playerIndex ) )
{
    // All Input calls inside this block query controller index 0 only
    if ( Input.Pressed( "Jump" ) )
    {
        // Make player 1 jump
    }
}

Input glyphs

Display the correct button icon for the player’s current device. Glyphs update automatically when players rebind keys or switch input devices, so fetch them each frame:
Texture jumpGlyph         = Input.GetGlyph( "jump" );
Texture jumpGlyphOutlined = Input.GetGlyph( "jump", true );
Use a glyph directly in a Razor panel with an <Image> element:
<Image Texture="@Input.GetGlyph( "jump", InputGlyphSize.Medium, true )" />
Fetch glyphs every frame rather than caching them — the texture changes when the player switches devices or rebinds a key.

Raw keyboard input

Use raw input only when named actions don’t fit your use case. Raw keys cannot be rebound by players.
You can bypass the action system and query physical keys directly:
if ( Input.Keyboard.Down( "W" ) )    Log.Info( "W is held" );
if ( Input.Keyboard.Pressed( "W" ) ) Log.Info( "W was pressed" );
if ( Input.Keyboard.Released( "W" ) ) Log.Info( "W was released" );
Key stringKey
"0""9"0–9
"a""z"A–Z
"KP_0""KP_9"Numpad 0–9
"KP_DIVIDE"Numpad /
"KP_MULTIPLY"Numpad *
"KP_MINUS"Numpad -
"KP_PLUS"Numpad +
"KP_ENTER"Numpad Enter
"KP_DEL"Numpad Delete
"ENTER"Enter
"SPACE"Space
"BACKSPACE"Backspace
"TAB"Tab
"CAPSLOCK"Caps Lock
"NUMLOCK"Num Lock
"ESCAPE"Escape
"SCROLLLOCK"Scroll Lock
"INS"Insert
"DEL"Delete
"HOME"Home
"END"End
"PGUP"Page Up
"PGDN"Page Down
"PAUSE"Pause
"SHIFT"Left Shift
"RSHIFT"Right Shift
"ALT"Left Alt
"RALT"Right Alt
"UPARROW"Up Arrow
"LEFTARROW"Left Arrow
"RIGHTARROW"Right Arrow
"DOWNARROW"Down Arrow
"SEMICOLON"Semicolon
"<"Less Than
">"More Than
"["Left Bracket
"]"Right Bracket
","Comma
"."Period
"/"Slash
"\\"Backslash
"-"Hyphen / Minus
"="Equals
"`"Backtick / Console key
"'"Apostrophe