Input API

January 6, 2026 ยท View on GitHub

The webcc::input module provides functions for handling keyboard and mouse input.

#include "webcc/input.h"

Initialization

Before receiving input events, you must initialize the respective input systems.

void init_keyboard();
void init_mouse(webcc::DOMElement handle); // handle is usually the canvas or body

Note: Canvas handles can be passed directly as they implicitly convert to DOMElement.

Pointer Lock

void request_pointer_lock(webcc::DOMElement handle);
void exit_pointer_lock();

Events

Input events are polled using the main event loop.

Keyboard Events

struct KeyDownEvent {
    int32_t key_code;
};

struct KeyUpEvent {
    int32_t key_code;
};

Mouse Events

struct MouseDownEvent {
    int32_t button;
    int32_t x;
    int32_t y;
};

struct MouseUpEvent {
    int32_t button;
    int32_t x;
    int32_t y;
};

struct MouseMoveEvent {
    int32_t x;
    int32_t y;
};