mouseWentDown()

Category:Game Lab

Checks if the mouse button specified was pressed.

Some interactive games use the mouse for the user to control the game. mouseWentDown() generates a single true value when the mouse button is pressed down, no matter how long the button is pressed. Use mouseDown() to continually check if the button is pressed.

Examples

Black and White

Change the background by clicking a mouse button.

// Change the background by clicking a mouse button.
function draw() {
  if (mouseWentDown("rightButton")) background("black");
  if (mouseWentDown("leftButton")) background("white");
}

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

Syntax

mouseWentDown(button)

Parameters

Name Type Required? 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