← Cheatsheets
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 System | Best For | Complexity |
| Input Manager (Old) | Quick prototyping, simple inputs | Low |
| Input System (New) | Production, rebinding, multi-device | Medium |
| Rewired (Asset) | Advanced rebinding, controller support | Medium |
| Custom | Niche requirements | High |
Unity Input System (New) Setup
- Install: Package Manager → Input System.
- Create Input Actions asset.
- Assign to PlayerInput or use C# events.
- Enable in Player Settings → Active Input Handling.
Action Types
| Type | Use |
| Button | Press/release, tap (jump, fire) |
| Value | Continuous axis (move, look) |
| Pass-Through | Raw value, no processing |
| Composite | Combine 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
| Composite | Example |
| 1D Axis | W/S or Up/Down |
| 2D Vector | WASD + Arrows |
| Button With One Modifier | Shift + Click |
| Button With Two Modifiers | Ctrl + 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
| Scheme | Devices |
| KeyboardMouse | Keyboard + Mouse |
| Gamepad | Xbox / PS / Switch controller |
| Touch | Mobile touchscreen |
| Joystick | Flight stick |
PlayerInput playerInput = GetComponent<PlayerInput>();
playerInput.SwitchCurrentControlScheme("Gamepad", Gamepad.current);
Input Tips
- Use new Input System for all new projects.
- Use
InputAction.CallbackContext.ReadValue<T>() instead of polling.
- Cache
Keyboard.current / Mouse.current / Gamepad.current.
- For UI: use EventSystem to avoid input double-processing.