Get the all keys that are currently pressed down.

Syntax getKeysDown()

Return Type Array


Get the keycodes of all 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

Array. Returns an array of numeric keycodes.


Example 1

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

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

var text = canvas.display.text({
	x: 177,
	y: 40,
	origin: { x: "center", y: "top" },
	align: "center",
	font: "bold 25px/1.5 sans-serif",
	text: "Keys pressed down:",
	fill: "#000"


canvas.bind("keydown keyup", function () {
	var keys = canvas.keyboard.getKeysDown();
	text.text = "Keys pressed down:\n" + keys.join("\n");