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

Register an event that runs when user presses certain keys.
// .jump() once when "space" is just being pressed
onKeyPress("space", () => {
    bean.jump()
});

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

sincev2000.1

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

Register an event that runs when user presses any key.
// Call restart() when player presses any key
onKeyPress((key) => {
    debug.log(`key pressed ${key}`)
    restart()
})

sincev3001.0

kaplay logo

3001.0.0-alpha.18

Misc