onKeyPress(key: Key | Key[], action: (key: Key)=>void): KEventController

Register an event that runs when user presses certain keys.

paramkey- The key(s) to listen for.

paramaction- The function to run when the event is triggered.

// .jump() once when "space" is just being pressed
onKeyPress("space", () => {
    bean.jump();
});

onKeyPress(["up", "space"], () => {
    bean.jump();
});

returnsThe event controller.

sincev2000.1

onKeyPress(action: (key: Key)=>void): KEventController

Register an event that runs when user presses any key.

paramaction- The function to run when the event is triggered.

// Call restart() when player presses any key
onKeyPress((key) => {
    debug.log(`key pressed ${key}`);
    restart();
});

returnsThe event controller.

sincev3001.0

kaplay logo

Misc

Layer