This demo demonstrate how to use basic keyboard and mouse input with Shaku.
Keys currently down (marked in red):
Keys input counter:
Key Code | Pressed | Released | Double-Pressed | Double-Released | Last Release Time | Last Press Time | Is Down |
---|
The following is few code examples on how to use the input manager. These are just the basics, for the full API please see the docs.
// everything below goes between startFrame() and endFrame()
// getting mouse button states
let mouseDown = Shaku.input.down('mouse_left');
let mouseRightDown = Shaku.input.down('mouse_right');
let mouseMiddleDown = Shaku.input.down('mouse_middle');
// was left mouse button pressed in the previous frame, and released right in this frame?
// this is useful to generate 'onclick' like behavior. this will be true for only 1 frame when user release the mouse button
let mouseReleasedNow = Shaku.input.released('mouse_left');
// was left mouse button released previous frame, but pressed down right in this frame?
// this is useful to generate 'onclick' like behavior. this will be true for only 1 frame when user press the mouse button
let mousePressedNow = Shaku.input.pressed('mouse_left');
// get keyboard arrows state
// you can get all keyboard keys with the following command: Object.keys(Shaku.input.KeyboardKeys)
let moveUp = Shaku.input.down('up');
let moveDown = Shaku.input.down('down');
let moveLeft = Shaku.input.down('left');
let moveRight = Shaku.input.down('right');
// you can also use 'released()' and 'pressed' with keyboard keys
// for example, attack when space is released:
if (Shaku.input.released('space')) {
doAttack();
}
// get mouse position
console.log("Mouse move x: " + Shaku.input.mousePosition.x);
console.log("Mouse move y: " + Shaku.input.mousePosition.y);