# How can I test with a function whether another function is being executed?

**URL:** https://discourse.processing.org/t/how-can-i-test-with-a-function-whether-another-function-is-being-executed/27460
**Category:** Coding Questions
**Created:** [January 29, 2021, 3:34pm UTC](https://discourse.processing.org/t/how-can-i-test-with-a-function-whether-another-function-is-being-executed/27460 "2021-01-29T15:34:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [January 29, 2021, 3:34pm UTC](https://discourse.processing.org/t/how-can-i-test-with-a-function-whether-another-function-is-being-executed/27460/1 "2021-01-29T15:34:57Z")

</div>

Hi I want the mousePressed () function to be executed whenever the mousePressed function is executed by the parent without having to write it into the function of the parent …

I hope you can help me 🙂

```auto
class Joystick extends PApplet {
  PApplet parent;

  PVector mainLoc;
  PVector stickLoc;

  PVector value;

  float mainRadius;
  float stickRadius;

  boolean onStick = false;

  boolean mouseDown = false;
  boolean mouseUp = true;
  Joystick(PApplet p, float x, float y, float rMain) {
    super();
    parent = p;
    mainLoc = new PVector(x, y);
    stickLoc = new PVector(x, y);
    value = new PVector(0, 0);
    mainRadius = rMain;
    stickRadius = rMain/3;
  }
  void update(float x, float y) {
    moveStick(x, y);
    show();
    updateValue();
  }
  void show() {
    parent.fill(180);
    parent.stroke(0);
    parent.ellipse(mainLoc.x, mainLoc.y, mainRadius*2, mainRadius*2);

    parent.fill(130);
    parent.noStroke();
    parent.ellipse(stickLoc.x, stickLoc.y, stickRadius*2, stickRadius*2);
  }
  void updateValue() {
    float x = map(stickLoc.x, mainLoc.x-mainRadius, mainLoc.x+mainRadius, -1, 1);
    float y = map(stickLoc.y, mainLoc.y-mainRadius, mainLoc.y+mainRadius, -1, 1);
    value.set(x, y);
  }
  void moveStick(float x, float y) {
    if (onStick) {
      float d = dist(x, y, mainLoc.x, mainLoc.y);
      if (d <= mainRadius) {
        stickLoc.set(x, y);
      } else {
        PVector sub = PVector.sub(new PVector(x, y), mainLoc);
        sub.normalize();
        stickLoc.set(mainLoc.x+(sub.x*mainRadius), mainLoc.y+(sub.y*mainRadius));
      }
    } else {
      stickLoc.set(mainLoc);
    }
    //if(parent.mousePressed && mouseDown == false){
    // mousePressed();
    // mouseDown = true;
    //}
  }
  void mousePressed() {
    float d = dist(mouseX, mouseY, mainLoc.x, mainLoc.y);
    if (d <= mainRadius) {
      onStick = true; 
      //stickLoc.set(mouseX, mouseY);
    } else {
      onStick = false;
    }
  }
  void mouseReleased() {
    onStick = false;
  }
}

```

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 29, 2021, 4:47pm UTC](https://discourse.processing.org/t/how-can-i-test-with-a-function-whether-another-function-is-being-executed/27460/2 "2021-01-29T16:47:23Z")

</div>

> [@Handle (and consume) mouse events in classes](https://discourse.processing.org/t/handle-and-consume-mouse-events-in-classes/17689/4):
>
> To my surprise, Processing doesn’t directly call back input events such as mousePressed(), keyReleased(), etc. open_mouth But only these 2 input events: mouseEvent() & keyEvent(). drooling_face So we can only use those 2 for registerMethod() as input events: /\*\* \* RegisterMethod MouseEvent (v1.0) \* GoToLoop (2020/Feb/10) \* \* https://Discourse.Processing.org/t/ \* handle-and-consume-mouse-events-in-classes/17689/4 \* \* https://GitHub.com/processing/processing/wiki/ \* Library-Basics#w…
