anyKeysDown()

Check if there are any keys that are currently pressed down.

Syntax anyKeysDown()

Return Type Boolean

Description

Check if there are any keys that are currently pressed down. Note: Due to hardware limitations of keyboards, only a few keys can be tracked simultaneously, usually around 6. This can disturb the result sometimes, when more keys are pressed down.

Return Value

Boolean. Returns true if any keys are pressed down, and false otherwise.

Examples

Example 1

We create a core instance and a text object that will show if any keys are pressed down. An event handler is bound to keydown and keyup, and that will update the text with the correct answer from anyKeysDown(). Click in the output and press down a key.

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: "Any keys pressed down?\nNo",
	fill: "#000"
});

canvas.addChild(text);

canvas.bind("keydown keyup", function () {
	text.text = "Any keys pressed down?\n" +
			(canvas.keyboard.anyKeysDown() ? "Yes" : "No");
	canvas.redraw();
});
Output