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
function draw() {
console.log(mouseDown("leftButton"));
}
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();
}
Syntax
mouseDown(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 support@code.org.