# With G4P Click Checkbox also triggers mouseClicked

**URL:** <https://discourse.processing.org/t/with-g4p-click-checkbox-also-triggers-mouseclicked/41559>\
**Category:** Libraries\
**Created:** [April 1, 2023, 5:08pm UTC](https://discourse.processing.org/t/with-g4p-click-checkbox-also-triggers-mouseclicked/41559 "2023-04-01T17:08:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [April 1, 2023, 5:08pm UTC](https://discourse.processing.org/t/with-g4p-click-checkbox-also-triggers-mouseclicked/41559/1 "2023-04-01T17:08:51Z")

</div>

With a G4P Checkbox when I click on it, the Processing mouseClicked() runs as well. In other environments where I’ve coded, the front-most window gets the click and doesn’t arrive on the ones behind. I’m finding myself adding code to the mouseClicked() to ignore the click if it’s on the Checkbox.

Am I missing the reason why it’s like this? Is it selectable not to have the mouseClick as well?

```auto
import g4p_controls.*;
GCheckbox cBox;
public void setup(){cBox = new GCheckbox(this, 20, 10, 80, 20, "CBox");}
void draw() {}
void mouseClicked() {println("mouseClicked");}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [April 1, 2023, 5:23pm UTC](https://discourse.processing.org/t/with-g4p-click-checkbox-also-triggers-mouseclicked/41559/2 "2023-04-01T17:23:11Z")

</div>

G4P registers itself with Processing so gets a _ **copy** _ of Processing events. It does _ **not replace** _ Processing’s event handling system.

So when you click the mouse button Processing triggers a mouse clicked event which causes the `mouseClicked` function to be executed. G4P also gets a copy of the event which it will process if the mouse is over a G4P control.

It is just how Processing works with third party libraries.

> [@RichardDL](#):
>
> In other environments where I’ve coded, the front-most window gets the click and doesn’t arrive on the ones behind.

True but there is only one “window” in the sketch code you posted.

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [April 1, 2023, 7:45pm UTC](https://discourse.processing.org/t/with-g4p-click-checkbox-also-triggers-mouseclicked/41559/3 "2023-04-01T19:45:38Z")

</div>

Thank you. Always good to know more of how it all works. I was thinking that the mouseClicked() code would have to know the coords of all the CheckBoxes. Now I’ve found that the G4P code runs before mouseClicked(). So it can set a boolean to indicate that the mouseClick should be ignored. Much more tidy.

```auto
import g4p_controls.*;
GCheckbox cBox;
boolean G4PClicked = false;
public void setup(){cBox = new GCheckbox(this, 20, 10, 80, 20, "CBox");}
void draw() {}
public void handleToggleControlEvents(GToggleControl checkbox, GEvent event) {G4PClicked = true;}
void mouseClicked() {
  if (G4PClicked) {G4PClicked = false;}
  else {print("mouseClicked ");}
}

```
