# Library that allows for mouse control

**URL:** https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969
**Category:** Coding Questions
**Created:** [July 25, 2019, 1:08pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969 "2019-07-25T13:08:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![WeinSim](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@WeinSim](https://discourse.processing.org/u/WeinSim)
#### Post date: [July 25, 2019, 1:08pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/1 "2019-07-25T13:08:13Z")

</div>

Ok, so I wanted to know wether there is some library that allows you to control what the mouse does (which buttons are being pressed and where it moves). I think I’ve seen something like this in c# or something idk and when googling for such a library I couldn’t find anything. Does anyone know about such a library (or perhaps even an already built-in function in Processing I didn’t know of)?  
Simon

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [July 25, 2019, 1:11pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/2 "2019-07-25T13:11:14Z")

</div>

You’re probably looking for [https://docs.oracle.com/javase/8/docs/api/java/awt/Robot.html](https://docs.oracle.com/javase/8/docs/api/java/awt/Robot.html)

---

<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: [July 25, 2019, 1:38pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/3 "2019-07-25T13:38:46Z")

</div>

This has been [discussed](https://www.google.com/search?as_sitesearch=processing.org&as_q=Robot+class) on the forum many times.

---

<div class="post-metadata">

### Author: ![WeinSim](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@WeinSim](https://discourse.processing.org/u/WeinSim)
#### Post date: [July 25, 2019, 1:52pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/4 "2019-07-25T13:52:49Z")

</div>

Thanks a lot, but how do I get it to work in Processing?

---

<div class="post-metadata">

### Author: ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)
#### Post date: [July 25, 2019, 2:13pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/5 "2019-07-25T14:13:09Z")

</div>

Like any other built-in Java library - you need to import it. For example (make sure you know how to quit using Escape!)

```auto
import java.awt.Robot;

Robot robot;
int x,y;

void setup() {
 try {
   robot = new Robot();
 } catch (Exception ex) {
  println(ex); 
 }
}

void draw() {
  x++;
  x %= 500;
  y++;
  y %= 500;
  robot.mouseMove(x,y);
}

```

If you’re using P2D / P3D it’s better to use the JOGL library for this though.

---

<div class="post-metadata">

### Author: ![WeinSim](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@WeinSim](https://discourse.processing.org/u/WeinSim)
#### Post date: [July 26, 2019, 9:40am UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/6 "2019-07-26T09:40:53Z")

</div>

Thank you! It works just as I wanted

---

<div class="post-metadata">

### Author: ![WeinSim](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@WeinSim](https://discourse.processing.org/u/WeinSim)
#### Post date: [July 26, 2019, 11:53am UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/7 "2019-07-26T11:53:52Z")

</div>

Just one more thing, when I want to press the left mouse button, which parameter do i need to put into the `robot.mousePress()` function?

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [August 5, 2019, 10:58pm UTC](https://discourse.processing.org/t/library-that-allows-for-mouse-control/12969/8 "2019-08-05T22:58:42Z")

</div>

> [@WeinSim](#):
>
> which parameter do i need to put into the `robot.mousePress()` function

I believe that is BUTTON1 – although I haven’t tested the ways of referring to it.

[https://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html](https://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html)

Note in particular:

```auto
int button = InputEvent.BUTTON1_MASK
int button = InputEvent.getMaskForButton(1); 
int button = InputEvent.getMaskForButton(MouseEvent.BUTTON1);

```
