Tags: unity, input, keyboard, mouse, gamepad, key-bindings, axis-smoothing, dead-zones, haptics, game-dev Last updated: 2026-06-27

Input Handling (Keyboard / Mouse / Gamepad) Cheatsheet

Quick Reference

Input SystemBest ForComplexity
Input Manager (Old)Quick prototyping, simple inputsLow
Input System (New)Production, rebinding, multi-deviceMedium
Rewired (Asset)Advanced rebinding, controller supportMedium
CustomNiche requirementsHigh

Unity Input System (New) Setup

  1. Install: Package Manager → Input System.
  2. Create Input Actions asset.
  3. Assign to PlayerInput or use C# events.
  4. Enable in Player Settings → Active Input Handling.

Action Types

TypeUse
ButtonPress/release, tap (jump, fire)
ValueContinuous axis (move, look)
Pass-ThroughRaw value, no processing
CompositeCombine multiple bindings (WASD + arrows)

Reading Input (C# Events)

using UnityEngine.InputSystem;

public InputAction moveAction;
public InputAction lookAction;

void OnEnable() {
    moveAction.Enable();
    lookAction.Enable();
    moveAction.performed += OnMove;
    moveAction.canceled += OnMove;
}

void OnDisable() { /* -= and disable */ }

void OnMove(InputAction.CallbackContext ctx) {
    inputDir = ctx.ReadValue<Vector2>();
}

Composite Bindings

CompositeExample
1D AxisW/S or Up/Down
2D VectorWASD + Arrows
Button With One ModifierShift + Click
Button With Two ModifiersCtrl + Shift + S

Keyboard

# Old Input Manager
if (Input.GetKey(KeyCode.W))          { }  # Held
if (Input.GetKeyDown(KeyCode.Space))  { }  # First frame
if (Input.GetKeyUp(KeyCode.E))        { }  # Released

# New Input System
Keyboard kb = Keyboard.current;
if (kb.wKey.isPressed) { }
if (kb.spaceKey.wasPressedThisFrame) { }

Mouse

# Old Input Manager
Input.mousePosition
Input.GetAxis("Mouse X") / "Mouse Y"
Input.GetMouseButton(0) / (1) / (2)

# New Input System
Mouse mouse = Mouse.current;
Vector2 pos = mouse.position.ReadValue();
Vector2 delta = mouse.delta.ReadValue();
bool clicked = mouse.leftButton.wasPressedThisFrame;

Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;

Gamepad

Gamepad pad = Gamepad.current;
Vector2 leftStick = pad.leftStick.ReadValue();
Vector2 rightStick = pad.rightStick.ReadValue();
bool southButton = pad.buttonSouth.wasPressedThisFrame;
float leftTrigger = pad.leftTrigger.ReadValue();   # 0–1
Vector2 dpad = pad.dpad.ReadValue();

Controller Rumble (Haptics)

Gamepad pad = Gamepad.current;
pad.SetMotorSpeeds(0.5f, 0.3f);    # Left 50%, Right 30%

IEnumerator Rumble(float duration, float low, float high) {
    pad.SetMotorSpeeds(low, high);
    yield return new WaitForSeconds(duration);
    pad.SetMotorSpeeds(0f, 0f);
}

Axis Smoothing

Vector2 currentVelocity;
Vector2 smoothInput = Vector2.SmoothDamp(
    smoothInput, rawInput, ref currentVelocity, 0.1f);

# Exponential moving average
smoothedInput = Vector2.Lerp(smoothedInput, rawInput, 10f * Time.deltaTime);

Dead Zones

Vector2 ApplyDeadZone(Vector2 input, float deadZone) {
    if (input.magnitude < deadZone)
        return Vector2.zero;
    return input.normalized *
        ((input.magnitude - deadZone) / (1f - deadZone));
}
# Or add Stick Deadzone processor in Input Actions asset

Key Rebinding (Runtime)

public InputActionReference actionRef;
public TextMeshProUGUI bindingText;

public void StartRebind() {
    var rebind = actionRef.action.PerformInteractiveRebinding()
        .OnMatchWaitForAnother(0.1f)
        .OnComplete(op => {
            bindingText.text = actionRef.action.GetBindingDisplayString();
            op.Dispose();
        })
        .WithControlsExcluding("Mouse")
        .Start();
}

string json = actionRef.action.SaveBindingOverridesAsJson();
PlayerPrefs.SetString("InputOverrides", json);

Multiple Control Schemes

SchemeDevices
KeyboardMouseKeyboard + Mouse
GamepadXbox / PS / Switch controller
TouchMobile touchscreen
JoystickFlight stick
PlayerInput playerInput = GetComponent<PlayerInput>();
playerInput.SwitchCurrentControlScheme("Gamepad", Gamepad.current);

Input Tips