Getting Raw Mouse Data

Hi, New to forum and to Processing. I am trying to get raw mouse data before Windows massages it. I am trying to keep track of rough position over a large 3 foot by 3 foot area. I have used this method to first update my large surface value by the new mouse position delta and then reset the pointer to the middle of the window each time there is mouse movement.

//attempt to get raw mouse data that allows capturing movement beyond window or screen

import com.jogamp.newt.opengl.GLWindow;
//import java.awt.*;
//import java.awt.event.*;

//Robot robot;

boolean drawpoint = false;

float rangex = 5000;
float rangey  = 5000;
float mapx = 0;
float mapy = 0;

float xxlong = 0;
float yylong = 0;

void setup() {
  size(1000, 1000, P2D);
  //  size(640, 640);
  //  size(1280, 720);
  background(0);
  noCursor();
  stroke(255, 0, 0);
  line(width/2 - 30, height/2, width/2 + 30, height/2);
  line(width/2, height/2 - 30, width/2, height/2 + 30);

  noFill();
  square(50, 50, height-100);

  //robot = new Robot();
  //robot.setAutoDelay(0);
  noFill();
}

void mouseMoved() {
  drawpoint = true;

  xxlong = xxlong + (mouseX - width/2);
  yylong = yylong + (mouseY - height/2);

  mapx = map(xxlong, 0, rangex, 0, width);
  mapy = map(yylong, 0, rangey, 0, height);


  //this resets pointer to center of window
  ((GLWindow)getSurface().getNative())
    .warpPointer(width / 2, height / 2);
}

void draw() {

  if (drawpoint) {
    stroke(255);
    point (mapx + width/2, mapy + height/2);
    drawpoint = false;
  }

  println("xxlong= " + xxlong + " yylong= " + yylong);
  println("mapx= " + mapx + " mapx= " + mapx);
  println("mapy= " + mapy + " mapy= " + mapy);
  println();

  if (mousePressed) {  
    if (mouseButton == CENTER) {
      xxlong = 0;
      yylong = 0;
      background(0);
      stroke(255, 0, 0);
      line(width/2 - 30, height/2, width/2 + 30, height/2);
      line(width/2, height/2 - 30, width/2, height/2 + 30);
      noFill();
      square(50, 50, height-100);
    } else if (mouseButton == LEFT) {
      
    } else {
    }
  }
}

It kind of works, but errors build up rapidly and position information is not very repeatable.

I wanted to see if I could do better by getting access to the unfiltered mouse data. I was wondering if there is a way of getting the raw mouse data by getting down to the HID level. I have seen some info using WM_INPUT and GetRawInputData, but not sure how to use it in the Processing environment.

Thanks for any help.

1 Like

After changing some settings in Mouse Properties, I’m getting better results. I slowed the pointer speed a bit and unchecked “Enhance pointer precision”. I have not looked into what that does. That helped making it more repeatable as long as I don’t move the mouse too quickly which is fine for my application. The error is now about 5% versus 25%.

Still would be interested to see if there is a way of getting the mouse raw X and Y data.

1 Like