Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

p5.js | doubleClicked() Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The doubleClicked() function is invoked whenever a mouse or pointing device causes a dblclick event. This happens when the pointing device is clicked twice in quick succession on a single element. The MouseEvent callback argument could be used to access the details of the click.



Parameters: This function accepts a single parameter as mentioned above and described below:

  • event: This is an optional MouseEvent callback argument. It can be used to access the click details.

The program below illustrate the doubleClicked() function in p5.js:

Example 1: Using double click to change the fill color.

let colorVal = 0;
function setup() {
  createCanvas(500, 300);
function draw() {
  // apply fill based on the red component
  fill(colorVal, 128, 255 - colorVal)
  text("Double click to change the color", 20, 20);
  circle(150, 150, 200);
function doubleClicked() {
  // change the value if
  // the event occurs
  if (colorVal < 255)
    colorVal += 50;
    colorVal = 0;


Example 2: Accessing the details of the MouseEvent object.

let y = 60;
function setup() {
  createCanvas(500, 200);
  text("Double click the mouse to see doubleClicked() function fire", 10, 20);
function doubleClicked(event) {
  // get the x and y location
  // of the double click
  locationX = event.x;
  locationY = event.y;
  locString = "Mouse was double clicked at location: "
    + locationX + ", " + locationY;
  text(locString, 10, y);
  y = y + 20;


Online editor:
Environment Setup:


My Personal Notes arrow_drop_up
Last Updated : 17 Jan, 2020
Like Article
Save Article
Similar Reads
Related Tutorials