Mouse Is Very Slow

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?

1 Like

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

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

1 Like

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.

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?

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

// 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

2 Likes

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?

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 ?

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.

1 Like

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

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

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);
}
1 Like

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

void mouseClicked() {}

about 5 % of clicks seem to be ignored

BUT when use

void mousePressed() {}

all smooth…
my full code:

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:

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
https://github.com/processing/processing/issues/4687 ,
but they blame it (possibly wrongly ) on OPENGL

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!

1 Like

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

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.

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.

sorry, can not see your picture

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

thanks for your time.

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

1 Like

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()
1 Like

why you think that is bad?

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.

1 Like

Hello,

https://processing.org/reference/mouseClicked_.html

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.

https://docs.oracle.com/javase/tutorial/uiswing/events/mouselistener.html
states:

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

The code I used to test this:

// 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!

:slight_smile:

3 Likes