A function that's called once when a mouse button is clicked twice quickly.
Declaring the function doubleClicked()
sets a code block to run automatically when the user presses and releases the mouse button twice quickly:
function doubleClicked() {
// Code to run.
}
The mouse system variables, such as mouseX and mouseY, will be updated with their most recent value when doubleClicked()
is called by p5.js:
function doubleClicked() {
if (mouseX < 50) {
// Code to run if the mouse is on the left.
}
if (mouseY > 50) {
// Code to run if the mouse is near the bottom.
}
}
The parameter, event
, is optional. doubleClicked()
is always passed a MouseEvent object with properties that describe the double-click event:
function doubleClicked(event) {
// Code to run that uses the event.
console.log(event);
}
On touchscreen devices, code placed in doubleClicked()
will run after two touches that occur within a short time.
Browsers may have default behaviors attached to various mouse events. For example, some browsers highlight text when the user moves the mouse while pressing a mouse button. To prevent any default behavior for this event, add return false;
to the end of the function.
Examples
Syntax
doubleClicked([event])
Parameters
optional MouseEvent
argument.
Related References
doubleClicked
A function that's called once when a mouse button is clicked twice quickly.
exitPointerLock
Exits a pointer lock started with requestPointerLock.
mouseButton
A String system variable that contains the value of the last mouse button pressed.
mouseClicked
A function that's called once after a mouse button is pressed and released.