Input

The engine provides keyboard and mouse input through GLFW, exposed to C# via NativeBridge.

Keyboard Input

Poll individual keys each frame:

if (NativeBridge.IsKeyPressed(NativeBridge.KEY_W))
{
    // W is held down
}

Available Key Constants

ConstantKey
KEY_W/A/S/DWASD movement
KEY_SPACEJump
KEY_Q/ECamera yaw
KEY_R/FCamera pitch
KEY_ESCAPEToggle cursor lock
KEY_TABToggle camera mode (FP/TP)
KEY_0Activate free camera (debug)
KEY_1Deactivate free camera
KEY_UP/DOWN/LEFT/RIGHTArrow keys

For other keys, pass the GLFW key code integer directly.

Mouse Input

Cursor Position

double mx, my;
NativeBridge.GetCursorPos(out mx, out my);

Returns the cursor position in window coordinates.

Cursor Lock

NativeBridge.SetCursorLocked(true);   // capture + hide cursor
NativeBridge.SetCursorLocked(false);  // release cursor

bool locked = NativeBridge.IsCursorLocked();

When locked, the cursor is hidden and raw mouse input is enabled for camera look. The CameraFollowSystem uses ESC to toggle this automatically.

Mouse Buttons

Poll individual mouse buttons each frame:

if (NativeBridge.IsMouseButtonPressed(NativeBridge.GLFW_MOUSE_BUTTON_LEFT))
{
    // Left mouse button is held down
}

Button Constants

ConstantValueButton
GLFW_MOUSE_BUTTON_LEFT0Left click
GLFW_MOUSE_BUTTON_RIGHT1Right click
GLFW_MOUSE_BUTTON_MIDDLE2Middle click (scroll wheel press)

Scroll Wheel

Read accumulated scroll delta and reset each frame:

float scrollX, scrollY;
NativeBridge.GetScrollOffset(out scrollX, out scrollY);
NativeBridge.ResetScrollOffset();
MethodDescription
GetScrollOffset(out float x, out float y)Read accumulated scroll delta since last reset
ResetScrollOffset()Reset the scroll accumulator to zero

The CameraFollowSystem uses scroll wheel for third-person camera zoom automatically.

Note

When the free camera is active (press 0), InputMovementSystem is disabled — WASD controls only the free camera. Press 1 to return to normal controls.

Input in Systems

The InputMovementSystem uses input for a physics-based player controller:

public static void InputMovementSystem(World world)
{
    var entities = world.Query(typeof(Movable), typeof(Transform), typeof(Rigidbody));
    foreach (int e in entities)
    {
        float inputX = 0f;
        float inputZ = 0f;
        if (NativeBridge.IsKeyPressed(NativeBridge.KEY_A)) inputX -= 1f;
        if (NativeBridge.IsKeyPressed(NativeBridge.KEY_D)) inputX += 1f;
        if (NativeBridge.IsKeyPressed(NativeBridge.KEY_W)) inputZ += 1f;
        if (NativeBridge.IsKeyPressed(NativeBridge.KEY_S)) inputZ -= 1f;

        // Convert input to camera-relative direction and set body velocity...

        bool jumpPressed = NativeBridge.IsKeyPressed(NativeBridge.KEY_SPACE);
        // Edge-detect space + grounded check, then apply jump vertical velocity...
    }
}

WASD movement is camera-relative when the entity has a Camera component. The player mesh rotates to face the move direction.