# Mouse Is Very Slow

**URL:** <https://discourse.processing.org/t/mouse-is-very-slow/16423>\
**Category:** Processing\
**Created:** [December 15, 2019, 7:00pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423 "2019-12-15T19:00:27Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 15, 2019, 7:00pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/1 "2019-12-15T19:00:27Z")

</div>

On at least two current projects, the mouse seems unreasonably slow. I am using mouseClicked to select options on the screen. Once clicked, I compute the location of the graphic on the screen that was clicked. Beyond that there is very little other activity at the moment. At times the mouse is responsive and sometimes it takes 2 or 3 clicks to wake up the mouse. Have you any suggestions as to what I might do to make the mouse react quicker than it does?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 16, 2019, 2:01am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/2 "2019-12-16T02:01:09Z")

</div>

any input like key or mouse is done  
“inbetween” the draw loops.  
so the question is does your code slow down the FPS?

a easy way to show can be inside draw() use

```auto
void setup() {
  size(400,300);
}
void draw() {
      surface.setTitle(" my project "+ nf(frameRate, 0, 1)+" FPS" );  
}

```

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 16, 2019, 1:06pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/3 "2019-12-16T13:06:02Z")

</div>

> [@kll](#):
>
> void setup() { size(400,300); } void draw() { surface.setTitle(" my project “+ nf(frameRate, 0, 1)+” FPS" ); }

I did as you suggested in a new sketch and the results were right at 60 fps.  
In order to try that in my problem sketch, I must make a few modifications. However at the moment, I must leave to go to work. I will try that again when I return home which will be later today.

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 16, 2019, 9:51pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/4 "2019-12-16T21:51:46Z")

</div>

I have returned home and have run some tests:

First, I should tell you that my current sketch is presently in the early stages of development. My sketch uses the full screen to display up 7 different gauges (clock, compass, speed, altitude, gradient, curvature, and text). The sketch will display any combination of the 7 in any order. Presently, I am testing the software to resize and display a simple rectangle in the place of each “gauge”. The software right now, has nothing in the Draw() function because the sketch is dependent upon the mouse being clicked to select or remove the various gauges (rectangle). So, nothing in the Draw loop could possibly effect the mouse because there is nothing there - its all mouse clicks.  
So I modified the sketch to use something less than full screen so I could see the frames per second results form your suggestion. It still showed 59 - 60 fps.  
Do you have any suggestions?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 17, 2019, 12:42am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/5 "2019-12-17T00:42:35Z")

</div>

if there is a empty draw() loop then  
the FPS will be 60 ( unless set differently or use different renderer? )

and the keyboard and mouse are “polled” 60 times per sec.

there might be some effects about FOCUS, so key only detected after mouse click canvas…

if the processing JAVA can not see the mouse there is a problem with OS or mouse.

* * *

try this

```auto
// kll bench and stress test with sysinfo and numinfo
// key [+] [-] [s]
// graphic card info only see with P2D P3D renderer

// rev 0.6 add mouse present and focus info

float rset=120, r;
int x = 0;
int w = 400;
int h = 200;
int grid=20, many = grid*grid;
boolean stressenable=true;

void settings() {
  // size(w, h); // default use JAVA2D 
  // size(w, h,FX2D);
  // size(w, h,P2D);
  size(w, h,P3D); //depricated size(w, h,OPENGL);
}

void setup() {
  frameRate(rset);
  background(200, 200, 0);
  numinfo();
  sysinfo();
  println("\nstresstest ( "+grid+"*"+grid+" = "+many+" ) points, [+][-] grid +-10" );
}

void draw() {
  surface.setTitle("SYS INFO set "+rset+": "+ nf(r, 0, 1)+" FPS" );
  if ( stressenable ) stress();
  r = frameRate;
  plot_fps();
  check_mouse();
}

void plot_fps() {
  if ( r > 30 ) stroke(0, 200, 0); 
  else stroke(200, 0, 0);
  line(x, height-2, x, height-2-r); // FPS graph
  x++;
  if ( x > width ) { 
    x = 0; 
    background(200, 200, 0);
  }
}

void stress() {
  push();
  for ( int i=0; i<grid; i++) {
    for ( int j=0; j<grid; j++) {
      stroke(random(255), random(255), random(255) );
      point(5+i, 5+j);
    }
  }  
  pop();
}

boolean mousePresent=false;

public void mouseExited() {
  mousePresent = false;
}

public void mouseEntered() {
  mousePresent = true;
}

void check_mouse() {
  push();
  fill(0,0,200);
  rect(width-110,0,110,20);
  fill(200);
  if ( mousePresent && focused ) text("focus + mouse",width-100,15);
  else if ( mousePresent ) text("mouse",width-100,15);
  else if ( focused ) text("focus",width-100,15);
  pop();
}

void sysinfo() {
  println( "__SYS INFO :");
  println( "System : " + System.getProperty("os.name") + " " + System.getProperty("os.version") );// + " " + System.getProperty("os.arch") );
  println( "JAVA : " + System.getProperty("java.home") + " rev: " +javaVersionName);
  //println( System.getProperty("java.class.path") );
  //println( "\n" + isGL() + "\n" );
  println( "OPENGL : VENDOR " + PGraphicsOpenGL.OPENGL_VENDOR+" RENDERER " + PGraphicsOpenGL.OPENGL_RENDERER+" VERSION " + PGraphicsOpenGL.OPENGL_VERSION+" GLSL_VERSION: " + PGraphicsOpenGL.GLSL_VERSION);
  println( "user.home : " + System.getProperty("user.home") );
  println( "user.dir : " + System.getProperty("user.dir") );
  println( "user.name : " + System.getProperty("user.name") );
  println( "sketchPath : " + sketchPath() );
  println( "dataPath : " + dataPath("") );
  println( "dataFile : " + dataFile("") );
  println( "frameRate : target "+nf(rset, 0, 1)+" actual "+nf(r, 0, 1));
  println( "canvas : width "+width+" height "+height+" pix "+(width*height));
}

void numinfo() {
  println( "__NUM INFO :");
  println( "byte "+Byte.SIZE+ " bit | min: "+Byte.MIN_VALUE+ "\t\t\t max: "+Byte.MAX_VALUE);
  println( "short "+Short.SIZE+ " bit | min: "+Short.MIN_VALUE+ "\t\t\t max: "+Short.MAX_VALUE);
  println( "int "+Integer.SIZE+" bit | min: "+Integer.MIN_VALUE+"\t\t max: " +Integer.MAX_VALUE);
  println( "long "+Long.SIZE+ " bit | min: "+Long.MIN_VALUE+ "\t max: " +Long.MAX_VALUE);
  println( "float "+Float.SIZE+ " bit | min: "+Float.MIN_VALUE+ "\t\t\t max: "+Float.MAX_VALUE);
  println( "double "+Double.SIZE+ " bit | min: "+Double.MIN_VALUE+ "\t\t\t max: "+Double.MAX_VALUE);
}

void keyPressed() {
  if ( key != 's' && key != '+' && key != '-' ) println("key "+key+" keyCode "+keyCode);
  if ( key == 's' ) stressenable = ! stressenable;
  if ( key == '+' ) {
    grid +=10;
    many = grid*grid;
    println("stresstest ( "+grid+"*"+grid+" = "+many+" ) points" );
  }
  if ( key == '-' ) {
    grid -=10;
    grid = constrain(grid,0,height);
    many = grid*grid;
    println("stresstest ( "+grid+"*"+grid+" = "+many+" ) points" );
  }
}

```

i added some mouse info for you

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 17, 2019, 4:38am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/6 "2019-12-17T04:38:37Z")

</div>

I have checked what I know about mouse sensitivity in Windows documentation and nothing seems to help. If the mouse is polled once in the draw loop, then it seems to me that the problem is in Processing or have I missed something? In several applications that I have written, the failure to respond to a mouseClicked in a satisfactory manner is common to all. What would you suggest that might further help determine the problem?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 17, 2019, 4:50am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/7 "2019-12-17T04:50:48Z")

</div>

show us your mouse click code  
( as a short but running test project )  
where you also see that problem.

also what you can report about the FPS :  
from your project and from my above bench code  
/ with mouse in / out canvas detect  
also about focus:  
if the canvas loose focus, the first mouse click is just for get focus ? please check ?

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 17, 2019, 1:37pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/8 "2019-12-17T13:37:09Z")

</div>

I will attend to that when I get back home later today. Would you elaborate a bit on what you mean by focus?

Thank you, I will get back as quickly as I can.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 17, 2019, 1:51pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/9 "2019-12-17T13:51:38Z")

</div>

usually focus means the window is **active**  
( you normally see on the windows border… )  
and processing has its internal focus detect,  
and that i build into the above tool for you, a little rect top right shows

> if processing see

- focus and
- mouse inside window.

hm i should have build in a click detect

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 17, 2019, 3:12pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/10 "2019-12-17T15:12:21Z")

</div>

just before I left, i wrote the sketch below. It sometimes fails to respond to the mouse.

```auto
import processing.serial.*;
void setup(){
size (900,900); // actual screen width is 1920 and height is 1080
PFont TimesNewRoman;
TimesNewRoman = createFont("Times New Roman", 60);
textFont(TimesNewRoman);
background (200);
println ("Starting ...");
}

void draw (){
surface.setTitle("Mouse click test: "+ nf(frameRate, 0, 1)+" FPS" );  
}

void mouseClicked (){
background (200);
text ("mouse clicked at " + mouseX + "/" + mouseY, 100,100);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 18, 2019, 12:44am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/11 "2019-12-18T00:44:29Z")

</div>

ha, confirm,  
i see here same problem…

play with the code for a better feedback…  
// win 10 / 64b // processing 3.5.3 / 64b //  
here what i found: its the

```auto
void mouseClicked() {}

```

> about 5 % of clicks seem to be ignored

BUT when use

```auto
void mousePressed() {}

```

all smooth…  
my full code:

```auto
import processing.serial.*;
void setup() {
  size (900, 900); // actual screen width is 1920 and height is 1080
  PFont TimesNewRoman;
  TimesNewRoman = createFont("Times New Roman", 15);
  textFont(TimesNewRoman);
  background (200);
  strokeWeight(5);
  stroke(0,0,200);
  println ("Starting …");
}

void draw () {
  surface.setTitle("Mouse click test: "+ nf(frameRate, 0, 1)+" FPS" );
}

void mousePressed() {
//void mouseClicked() {
// background (200);
  fill(0);
  rect(0,0,200,20);
  fill(200);
  text("mouse clicked at " + mouseX + "/" + mouseY, 15, 15);
  point(mouseX,mouseY);
  println("mouse clicked at " + mouseX + "/" + mouseY);
}

```

* * *

if that can be confirmed by someone we could make a issue report.

minimal test code:

```auto
void setup() {
  size (500, 500);
  background (255);
  strokeWeight(5);
  stroke(0);
}

void draw () {}

//void mousePressed() {
void mouseClicked() {
  point(mouseX,mouseY);
  println("mouse clicked at " + mouseX + "/" + mouseY);
}

```

there is a report  
[mouseClicked() doesn't fire when you use P2D or P3D renderer and call cursor in draw() · Issue #4687 · processing/processing · GitHub](https://github.com/processing/processing/issues/4687) ,  
but they blame it (possibly wrongly ) on OPENGL

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 18, 2019, 12:51pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/12 "2019-12-18T12:51:38Z")

</div>

I copied your version of my mouse text sketch and changed mousePressed back to mouseClicked. I ran 10 tests and counted the dots until I clicked the mouse without a response. Here are

the results"

Test Number Clicks Until Failure

1 8

2 4

3 10

4 10

5 5

6 0

7 6

8 2

9 1

10 6

I then replaced the mouseCLicked with a mousePressed and I could not get it to fail at all…

I would say that you found the problem and I would think that there is an issue here to be reported.

My thanks for your help on this!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 18, 2019, 1:21pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/13 "2019-12-18T13:21:58Z")

</div>

yes, thanks for dig on…  
but i think it is a little bit more complicated,

-a- i could confirm a similar problem on  
Raspberry Pi Raspbian Buster ( 1st image ) / processing 3.5.3

-b- but there i note what i backward could confirm on win 10 too, the

```auto
void mouseClicked(){}

```

work ( mostly ) if you position mouse, wait , and click

if you move the mouse and click it while moving it not work at all!

( conflicting timer for DRAG detect? )

this way very different statistic failure rate comes up.  
( and OS mouse adjustments might play into too )

also the problem can be more bad, directly after start sketch??  
did you notice that too?

-c- could you give/confirm processing and windows version pls.

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 18, 2019, 4:44pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/14 "2019-12-18T16:44:20Z")

</div>

I ran the test sketch again and waited a full second after stopping mouse movement before clicking the mouse. No failures.

I ran it again but did not wait after the movement and experienced the same error rate as before.

I am attaching a document that answers your questions about my computer system.

 ![KLL_Processing_Questions.jpg](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/102f98d2a753923c60f4e7e0f50147822ae9d4be.jpeg)

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 19, 2019, 2:04am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/15 "2019-12-19T02:04:55Z")

</div>

sorry, can not see your picture

please check  
[https://github.com/processing/processing/issues/5971](https://github.com/processing/processing/issues/5971) ,  
and add more info there.

thanks for your time.

---

<div class="post-metadata">

**Author:** ![fredstout](https://avatars.discourse-cdn.com/v4/letter/f/258eb7/32.png) [@fredstout](https://discourse.processing.org/u/fredstout)\
**Post date:** [December 19, 2019, 4:08am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/16 "2019-12-19T04:08:34Z")

</div>

For some reason, answers to your questions failed to load so I recreated it and it is attached.

 ![KLL_Questions.jpg](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6bc46d91f9984bd7b7b100ca4e0029de4ad23c48.jpeg)

---

<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:** [December 22, 2019, 4:17am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/17 "2019-12-22T04:17:16Z")

</div>

Two observations, which might be helpful or might be unrelated:

1. text() uses lazy loading, and lags substantially the very first time it loads. If you need responsive events, don’t tie one to the very first instance of a text() call. Call text() earlier to prime it.
2. perhaps use mouseReleased() instead of mouseClicked() – not mousePressed()

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 22, 2019, 4:42am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/18 "2019-12-22T04:42:50Z")

</div>

> [@jeremydouglass](#):
>
> – not mousePressed()

why you think that is bad?

---

<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:** [December 22, 2019, 6:07am UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/19 "2019-12-22T06:07:20Z")

</div>

Not bad–it is just that mousePressed _may_ be inconsistent in how many events it sends across different graphics modes, operating systems, and physical hardware. mouseReleased isn’t – it generally corresponds to a click.

This is a much bigger deal with keyPressed vs keyReleased (!) but it can be one more way of simplifying debugging – ensure you are dealing with only one event.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 22, 2019, 2:40pm UTC](https://discourse.processing.org/t/mouse-is-very-slow/16423/20 "2019-12-22T14:40:11Z")

</div>

Hello,

> **[mouseClicked() / Reference](https://processing.org/reference/mouseClicked_.html)**
>
> The mouseClicked() function is called after a mouse button has been pressed and then released. Mouse and keyboard events only work when a program has draw(). Without \<…

mouseClicked() in Processing behaves the same as in Java.  
The Processing reference does not clearly state this but it **only** generates an event if the mouse is **not** moved.

> **[How to Write a Mouse Listener (The Java™ Tutorials \>        
           ...](https://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html)**
>
> This Swing Java Tutorial describes developing graphical user interfaces (GUIs) for applications and applets using Swing components

states:

> If you did not move the mouse, a mouse-clicked event will follow.

The code I used to test this:

```auto
// MouseClicked() behaviour

boolean flag1 = false;
boolean flag2 = false;

int count1, count2;

void setup()
  {
  size (900,900);
  background (200);
  textSize(48);
  fill(255, 255, 0);
  println ("Starting ...");
  background(0);
  }

void draw()
  {
  surface.setTitle("Mouse click test:" + nf(frameRate, 0, 1) + " FPS");  
  
  if (flag1)
    {
    background(0);
    text ("Mouse click at: " + mouseX + ", " + mouseY, 100, 100);
    text("mouseClicked() count:\n" + "mouseReleased() count:\n", 100, 200);
    text(count1 + "\n" + count2, 700, 200);
    flag1 = false;
    }     
  }

// Processing
//void mouseClicked()
// {
// flag1 = true;
// count1++;
// println(count1);
// }

// Java   
public void mouseClicked(MouseEvent e)
  {
  flag1 = true;
  count1++;  
  println("Mouse clicked (# of clicks: " + e.getClickCount() + ")", e);
  }  
  
void mouseReleased()
  {
  flag1 = true;
  count2++;
  println("count2: ", count2);
  }

```

Good to know!

🙂
