πŸ“Œ Browser Events in GameCrom

What are they?

In the GameCrom engine, besides the built-in input API functions (IsAnyPressed, IsAnyJustPressed, etc.), you can also use the native browser events to detect keys, mouse clicks, or touch interactions.

These events always work, even when the game is paused, because they come directly from the browser and do not depend on the engine's internal loop.

Note:
Browser events are perfect for:

Keyboard Events

keydown

Triggered when a key is pressed down. Always works, even while paused.


document.addEventListener("keydown", e => {
    console.log("Key pressed:", e.key);
});

keyup

Triggered when a key is released.


document.addEventListener("keyup", e => {
    console.log("Key released:", e.key);
});

πŸ–±οΈ Mouse Events

mousedown


document.addEventListener("mousedown", e => {
    console.log("Mouse button:", e.button);
});

mouseup


document.addEventListener("mouseup", e => {
    console.log("Mouse button released:", e.button);
});

mousemove


document.addEventListener("mousemove", e => {
    console.log("Mouse moved:", e.clientX, e.clientY);
});

πŸ“± Touch Events

touchstart


document.addEventListener("touchstart", e => {
    console.log("Touch start");
});

touchend


document.addEventListener("touchend", e => {
    console.log("Touch end");
});

touchmove


document.addEventListener("touchmove", e => {
    console.log("Touch move");
});

⏸️ Full Example: Pause with Escape

This example shows how to use keydown together with Pause() and Resume().


document.addEventListener("keydown", e => {
    console.log("KEY PRESSED:", e.key);

    if (e.key == "Escape") {

        if (paused == false) {
            Pause();
            Log("Pause");
        } else {
            Resume();
            Log("Resume");
        }
    }
});
Recommendation:
Use keydown for global keys or menus.
Use the engine API for character controls or gameplay logic.

πŸ“˜ Summary of all available event types

All these events can be used from any game script.