# Handle (and consume) mouse events in classes

**URL:** <https://discourse.processing.org/t/handle-and-consume-mouse-events-in-classes/17689>\
**Category:** Coding Questions\
**Created:** [February 10, 2020, 4:16pm UTC](https://discourse.processing.org/t/handle-and-consume-mouse-events-in-classes/17689 "2020-02-10T16:16:24Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [February 11, 2020, 1:30am UTC](https://discourse.processing.org/t/handle-and-consume-mouse-events-in-classes/17689/4 "2020-02-11T01:30:23Z")

</div>

To my surprise, Processing doesn’t directly call back input events such as **mousePressed()**, **keyReleased()**, etc. 😮

But only these 2 input events: **mouseEvent()** & **keyEvent()**. 🤤

So we can only use those 2 for **registerMethod()** as input events:

```auto
/**
 * 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#when-drawing-or-code-that-manipulates-a-sketch-can-occur
 */

static final int INSTANCES = 3;
final SomeClass[] consumers = new SomeClass[INSTANCES];

void setup() {
  noLoop();
  for (int i = 0; i < INSTANCES; consumers[i] = new SomeClass(i++));
}

public class SomeClass {
  int val;

  SomeClass(final int num) {
    val = num;
    registerMethod("mouseEvent", this);
  }

  void mouseEvent(final MouseEvent evt) {
    if (evt.getAction() == MouseEvent.PRESS) mousePressed();
  }

  void mousePressed() {
    print(val, TAB);
  }
}

```

Check out this wiki link below for more details on how to use those 2 input events: 🧐

- [GitHub.com/processing/processing/wiki/Library-Basics#when-drawing-or-code-that-manipulates-a-sketch-can-occur](http://GitHub.com/processing/processing/wiki/Library-Basics#when-drawing-or-code-that-manipulates-a-sketch-can-occur)

---

_[View the full topic](https://discourse.processing.org/t/handle-and-consume-mouse-events-in-classes/17689)._
