Razorbill
Scripting API

Input

Keyboard

is_key_down

Check if a key is currently held down.

bool is_key_down(ScriptContext* ctx, int key_code);

Returns true every frame the key is held.

is_key_pressed

Check if a key was pressed this frame (single trigger).

bool is_key_pressed(ScriptContext* ctx, int key_code);

Returns true only on the frame the key transitions from up to down.

Common Key Codes

KeyCodeKeyCode
W87Space32
A65Left Shift340
S83Left Ctrl341
D68Escape256
E69Enter257
Q81Tab258
F70Backspace259
0-948-57F1-F12290-301
Arrow Up265Arrow Down264
Arrow Left263Arrow Right262

Key codes follow the GLFW convention. Cast the KeyCode enum to int.


Mouse

get_mouse_position

Get the mouse position in window coordinates.

void get_mouse_position(ScriptContext* ctx, float* out_x, float* out_y);

get_mouse_delta

Get per-frame mouse movement in raw pixels. Returns zero on the first frame after cursor capture.

void get_mouse_delta(ScriptContext* ctx, float* out_dx, float* out_dy);

is_mouse_button_down

Check if a mouse button is currently held.

bool is_mouse_button_down(ScriptContext* ctx, int button_code);
ButtonCode
Left0
Right1
Middle2

Cursor Capture

set_cursor_captured

Lock or unlock the cursor for FPS-style mouse look. When captured, the cursor is hidden and mouse deltas are raw movement values.

void set_cursor_captured(ScriptContext* ctx, bool captured);

is_cursor_captured

Query the current cursor capture state.

bool is_cursor_captured(ScriptContext* ctx);

Example: FPS Mouse Look

static float yaw = 0, pitch = 0;
static const float sensitivity = 0.003f;

void OnStart(ScriptContext* ctx) {
    ctx->set_cursor_captured(ctx, true);
}

void OnUpdate(ScriptContext* ctx) {
    // Toggle cursor capture with Escape
    if (ctx->is_key_pressed(ctx, 256)) {
        bool captured = ctx->is_cursor_captured(ctx);
        ctx->set_cursor_captured(ctx, !captured);
    }

    if (!ctx->is_cursor_captured(ctx)) return;

    float dx, dy;
    ctx->get_mouse_delta(ctx, &dx, &dy);

    yaw -= dx * sensitivity;
    pitch -= dy * sensitivity;

    // Clamp pitch
    if (pitch > 1.5f) pitch = 1.5f;
    if (pitch < -1.5f) pitch = -1.5f;

    // Convert euler to quaternion (yaw then pitch)
    float cy = cosf(yaw * 0.5f), sy = sinf(yaw * 0.5f);
    float cp = cosf(pitch * 0.5f), sp = sinf(pitch * 0.5f);

    float rot[4] = {
        cy * sp,    // x
        sy * cp,    // y
        -sy * sp,   // z
        cy * cp     // w
    };
    ctx->set_rotation(ctx->self, rot);
}

Example: WASD Movement

void OnUpdate(ScriptContext* ctx) {
    float dt = ctx->get_delta_time();
    float speed = 5.0f;
    float pos[3];
    ctx->get_position(ctx->self, pos);

    if (ctx->is_key_down(ctx, 87)) pos[2] -= speed * dt; // W - forward
    if (ctx->is_key_down(ctx, 83)) pos[2] += speed * dt; // S - backward
    if (ctx->is_key_down(ctx, 65)) pos[0] -= speed * dt; // A - left
    if (ctx->is_key_down(ctx, 68)) pos[0] += speed * dt; // D - right

    ctx->set_position(ctx->self, pos);
}

On this page