# Multiple mouse clicks issue

**URL:** https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126
**Category:** Coding Questions
**Created:** [December 10, 2020, 8:45pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126 "2020-12-10T20:45:56Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)
#### Post date: [December 10, 2020, 8:45pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/1 "2020-12-10T20:45:56Z")

</div>

How do I consider multiple mouse clicks as one mouse click?  
I have an if condition which checks for mouse click condition and increments the counter variable, but when mouse is kept pressed for a long time, there are multiple mouse clicks but I want the counter variable to increment only by one.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 10, 2020, 8:51pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/2 "2020-12-10T20:51:19Z")

</div>

when you use the function mousePressed() as opposed to the boolean variable mousePressed it’s better

see reference

- function mousePressed() is with brackets ()
- the boolean variable mousePressed is without the brackets ()

---

<div class="post-metadata">

### Author: ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)
#### Post date: [December 10, 2020, 8:53pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/3 "2020-12-10T20:53:01Z")

</div>

this is the code. What change do I do here?

```auto
if (mousePressed and mouseClicked and mouseX > 500 and mouseX < 600 and mouseY > 500 and mouseY < 600):
               count+=1

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 10, 2020, 8:53pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/4 "2020-12-10T20:53:37Z")

</div>

when you use the function mousePressed() as opposed to the boolean variable mousePressed it’s better

see reference

---

<div class="post-metadata">

### Author: ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)
#### Post date: [December 10, 2020, 8:56pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/5 "2020-12-10T20:56:27Z")

</div>

when i replace mousePressed with mousePressed() in if condition, it shows an error saying bool object not callable.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 10, 2020, 8:57pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/6 "2020-12-10T20:57:18Z")

</div>

here is the reference for mousePressed() - the function

see [https://www.processing.org/reference/mousePressed\_.html](https://www.processing.org/reference/mousePressed_.html)

---

<div class="post-metadata">

### Author: ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)
#### Post date: [December 10, 2020, 9:04pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/7 "2020-12-10T21:04:11Z")

</div>

still I want it to count only once in that particular region/area.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 10, 2020, 9:04pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/8 "2020-12-10T21:04:53Z")

</div>

Does it work now?

Please show your entire running code to get real help.

---

<div class="post-metadata">

### Author: ![niko](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@niko](https://discourse.processing.org/u/niko)
#### Post date: [December 10, 2020, 9:23pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/9 "2020-12-10T21:23:43Z")

</div>

I suppose you wrote the condition you posted inside the draw() function. It is then evaluated every time the draw function is called.  
I guess that what you want is to write the condition inside the mouseClicked() function as Chrisir said. It would look like so:

```auto
void mouseClicked() {
   if(mouseX > 500 & mouseX < 600 && mouseY > 500 && mouseY < 600) count += 1;
}

```

The mouseClicked function is automatically called once for each time the mouse is pressed and then released.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 10, 2020, 9:41pm UTC](https://discourse.processing.org/t/multiple-mouse-clicks-issue/26126/10 "2020-12-10T21:41:51Z")

</div>

Yeah, and the mousePressed () function too.

`mousePressed` as a boolean variable registers multiple times

```auto

int count = 0; 

void setup() {
  size(600, 600);
  background(0);
}

void draw() {
  background(0); 
  text(count, 3, 13);

  if (mousePressed && 
    mouseX > 500 && 
    mouseX < 600 &&
    mouseY > 500 &&
    mouseY < 600)
    count+=1;
}

```

* * *

`mousePressed()` as a function registers only ONCE

```auto

int count = 0; 

void setup() {
  size(600, 600);
  background(0);
}

void draw() {
  background(0); 
  text(count, 3, 13);
}

//----------------------------------------------------------
// Input functions 

void mousePressed() {
  if ( mouseX > 500 && 
    mouseX < 600 &&
    mouseY > 500 &&
    mouseY < 600)
    count+=1;
}

```
