mouseDown()

Category:Game Lab

Checks if the mouse button specified is pressed.

Some interactive games use the mouse for the user to control the game.

Examples

Pencil Drawing

Simple pencil drawing with mouseDown().

// Simple pencil drawing with mouseDown().
var sprite = createSprite(200, 200, 5, 5);
World.frameRate=60;
function draw() {
  sprite.x=World.mouseX;
  sprite.y=World.mouseY;
  if (mouseDown("leftButton")) drawSprites();
}

function draw() {
  console.log(mouseDown("leftButton"));
}

Syntax

mouseDown(button)

Parameters

NameTypeRequired?Description
button String The mouse button you want to check, either "leftButton" or "rightButton".

Returns

Boolean true or false.

Tips

  • When testing your games that use keyboard or mouse input make sure you click in the display area before you run, otherwise the Workspace will record your keyboard and mouse actions.

Found a bug in the documentation? Let us know at documentation@code.org