Multitouch screen handling in Processing 4

Hi,

I’m trying to make multitouch work in Processing 4. Onece upon a time in Processing 2, there was a library which seemed to to just that : SMT for Simple Multi Touch.

Unfortunately, Processing 3 dropped the support for JFrame, something to do with PApplet. No worry, I found some suggestions using a processing.awt.PSurfaceAWT object to get access to the Frame. Great.

But wait, in Processing 4 the support for awt stuff has been dropped. So I’m back to square one.

I’d rather not convert my project to P5.js or go back to Processing 2. Any idea on how to make it work? Could I use an external Java library like JWinPointer and if yes then how?

Thanks.

JavaFX supposedly handles touch events. Try this with a sketch in FX2D renderer mode.

var canvas = ((Canvas) surface.getNative());
canvas.setOnTouchMoved(e -> {
	e.getTouchPoints().forEach(point -> {
		// TODO
	});
});

These are the methods available:

image

2 Likes

Thanks for your suggestion. I’ve made some progress with this sketch:

import processing.javafx.*;
import javafx.scene.canvas.*;
import javafx.*;
import javafx.application.*;

void setup(){
  
  size(800,600, FX2D);
  surface = (PSurfaceFX) getSurface();
  Canvas canvas = ((Canvas)surface.getNative());
  
  canvas.setOnTouchMoved(e -> {
        println(e);
    e.getTouchPoints().forEach(point -> {
      print("setOnTouchMoved");
      println(point);
    });
  });
  canvas.setOnTouchPressed(e -> {
        println(e);
      e.getTouchPoints().forEach(point -> {
        print("setOnTouchPressed");
        println(point);
      });
    });
  canvas.setOnTouchReleased(e -> {
        println(e);
      e.getTouchPoints().forEach(point -> {
        print("setOnTouchReleased");
        println(point);
      });
    });
  canvas.setOnTouchStationary(e -> {
        println(e);
      e.getTouchPoints().forEach(point -> {
        print("setOnTouchStationary");
        println(point);
      });
    });
    
   canvas.setOnMousePressed(e -> {
        println(e);
      
    });
    
    println(Platform.isSupported(ConditionalFeature.INPUT_TOUCH));
    println(Platform.isSupported(ConditionalFeature.INPUT_MULTITOUCH));
}

void draw(){
}

To run it I’ve had to copy (not move !) javafx.base.jar and javafx.graphics.jar from C:\Users\Utilisateur\Documents\Processing\libraries\javafx\library\windows-amd64\modules\ to C:\Users\Utilisateur\Documents\Processing\libraries\javafx\library\

Good news is it finally runs, bad news is INPUT_TOUCH and INPUT_MULTITOUCH are disabled. The mouse events are detected but the touch events are not, or to be more precise they are detected as mouse events, which don’t handle multi-touch.

Can I enable ConditionalFeature.INPUT_TOUCH with javafx?

1 Like

I’ve seen people suggest adding -Dcom.sun.javafx.touch=true to the command line. Is there a way to add args when running a processing program?

System.setProperty("com.sun.javafx.touch", "true");

Thank you for posting this finding; I can now do a little bit more with JavaFX in v. 4.0.1.