mouseWentDown()
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
function draw() {
console.log(mouseWentDown("leftButton"));
}
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");
}
Syntax
mouseWentDown(button)
Parameters
Name | Type | Required? | Description |
---|---|---|---|
button | String | The mouse button you want to check, either "leftButton" or "rightButton". |
Returns
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 support@code.org.