numKeysDown()

Get the number of keys that are currently pressed down.

Syntax numKeysDown()

Return Type Number

Description

Get the number of keys that are currently pressed down. Note: Due to hardware limitations of keyboards, only a few keys can be tracked simultaneously, usually around 6.

Return Value

Number. Returns the number of keys that are currently pressed down.

Examples

Example 1

We create a core instance and a text object that will show the number of keys that are pressed down. An event handler is bound to keydown and keyup, and that will update the text with the return value from numKeysDown(). Click in the output and press down some keys.

View Example
Code
var canvas = oCanvas.create({
	canvas: "#canvas",
	background: "#ccc"
});

var text = canvas.display.text({
	x: 177,
	y: 140,
	origin: { x: "center", y: "top" },
	align: "center",
	font: "bold 25px/1.5 sans-serif",
	text: "Number of keys\n0",
	fill: "#000"
});

canvas.addChild(text);

canvas.bind("keydown keyup", function () {
	text.text = "Number of keys\n" +
			canvas.keyboard.numKeysDown();
	canvas.redraw();
});
Output