Input

Overview

The engine provides three static input helpers: KeyboardManager for keyboard state, BetterMouse for mouse state, and LittleBetterKeyboard for per-instance keyboard tracking. The FPS template also includes a PlayerInput helper that wraps common action bindings into a cleaner API for player controllers.

All input is polled once per frame during the engine’s update loop. You read it from your controller’s OnUpdate().

KeyboardManager

KeyboardManager is a static class that tracks the current and previous keyboard states. All keys use MonoGame’s Keys enum.

KeyboardManager.IsPressed(key)

True while the key is held down this frame.

KeyboardManager.HasBeenPressed(key)

True only on the frame the key was first pressed. Use this for one-shot actions like jumping, firing, or opening menus.

KeyboardManager.HasBeenReleased(key)

True only on the frame the key was released.

KeyboardManager.GetPressedKeys()

Returns an array of all keys currently held down.

if (KeyboardManager.HasBeenPressed(Keys.Space))
{
    entity.velocity.Y = jumpSpeed;
}


if (KeyboardManager.IsPressed(Keys.W))
{
    entity.velocity += forward * moveSpeed;
}

BetterMouse

BetterMouse is a static class for mouse state. It tracks button presses, releases, and cursor movement.

BetterMouse.leftDown / rightDown / middleDown

True while the respective button is held.

BetterMouse.WasLeftPressed()

True only on the first frame the left button was pressed.

BetterMouse.WasRightPressed()

True only on the first frame the right button was pressed.

BetterMouse.GetMovement()

Returns a Vector2 of cursor delta since the last frame. In locked cursor mode this gives you look input.

BetterMouse.GetScrollDir()

Returns -1, 0, or 1 based on scroll wheel direction this frame.

Vector2 mouseDelta = BetterMouse.GetMovement();
yaw += mouseDelta.X * mouseSensitivity;
pitch += mouseDelta.Y * mouseSensitivity;

Note

Mouse movement is only meaningful when the cursor is locked. The engine locks the cursor automatically when a map is loaded. You can check or control cursor lock state with MainEngine.LockMouse() and MainEngine.UnlockMouse().

LittleBetterKeyboard

LittleBetterKeyboard is an instance-based version of KeyboardManager. Because it’s not static, multiple controllers can each have their own independent keyboard tracker without sharing state. It’s useful for split-screen setups or any situation where two systems need separate “has been pressed” tracking for the same key.

LittleBetterKeyboard kb = new LittleBetterKeyboard();


// In OnUpdate:
kb.GetState();
if (kb.HasBeenPressed(Keys.E)) { /* interact */ }

You need to call kb.GetState() once per frame before checking any keys, just like the static version. Unlike the static version, the global KeyboardManager.GetState() call in the engine loop doesn’t populate it; you call it manually.

PlayerInput (FPS Template)

The FPS template includes a PlayerInput class that wraps the raw keyboard and mouse APIs into named action booleans. It’s not part of the engine itself, but it’s a useful reference for how to cleanly organize input in your own code.

Actions like playerInput.Jump(), playerInput.PrimaryFire(), and playerInput.Crouch() are properties that internally call the appropriate KeyboardManager or BetterMouse methods. Centralizing input bindings here means you only change one place when rebinding keys rather than hunting through every controller.

Consider doing the same in your own projects: a static or instanced input map class that converts raw key checks into named game actions.

Cursor Lock State

Whether the cursor is locked to the center of the window is controlled by MainEngine.DefaultCursorLockState, which the FPS template sets to true. When locked, the cursor is hidden and recentered each frame so BetterMouse.GetMovement() gives you relative look deltas.

The engine automatically unlocks the cursor when the game is paused or a menu is open, and relocks it when play resumes. If you open a custom UI that needs the cursor visible, call MainEngine.UnlockMouse() and MainEngine.LockMouse() to bracket it.

Set MainEngine.DefaultCursorLockState = false at startup if your game is a top-down or point-and-click style that never wants the cursor locked.