onMousePress(action: (m: MouseButton)=>void): KEventController

Register an event that runs when user clicks mouse.

paramaction- The function that is run when user clicks a mouse button.

// gives cookies on left press, remove on right press
let cookies = 0;
onMousePress(["left", "right"], (m) => {
    if (m == "left") {
        cookies++;
    } else {
        cookies--;
    }
});

returnsThe event controller.

sincev3001.0

onMousePress(btn: MouseButton | MouseButton[], action: (m: MouseButton)=>void): KEventController

Register an event that runs when user clicks mouse.

parambtn- The mouse button(s) to listen for. See

paramaction- The function that is run what the user clicks cetain mouse buttons.

// gives cookies on any mouse press
let cookies = 0;
onMousePress((m) => {
    cookies++;
    debug.log(`Cookies: ${cookies}`);
});

returnsThe event controller.

sincev3001.0

kaplay logo

Misc

Layer