function getMousePos(canvas, w, h, evt) {
            if (evt && !evt.clientX) {
              // use touches if touch and not mouse
              if (evt.touches) {
                evt = evt.touches[0];
              } else if (evt.changedTouches) {
                evt = evt.changedTouches[0];
              }
            }
            var rect = canvas.getBoundingClientRect();
            var sx = canvas.scrollWidth / w || 1;
            var sy = canvas.scrollHeight / h || 1;
            return {
              x: (evt.clientX - rect.left) / sx,
              y: (evt.clientY - rect.top) / sy,
              winX: evt.clientX,
              winY: evt.clientY,
              id: evt.identifier
            };
          }
The boolean system variable mouseIsPressed is true if the mouse is pressed
and false if not.

@property {Boolean} mouseIsPressed
@readOnly

@example
<div>
<code>
function draw() {
  background(237, 34, 93);
  fill(0);

  if (mouseIsPressed) {
    ellipse(50, 50, 50, 50);
  } else {
    rect(25, 25, 50, 50);
  }

  print(mouseIsPressed);
}
</code>
</div>

@alt
black 50x50 rect becomes ellipse with mouse click/press. fuchsia background.