# Multitouch screen handling in Processing 4

**URL:** <https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331>\
**Category:** Libraries\
**Created:** [August 12, 2022, 9:35pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331 "2022-08-12T21:35:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![KickMe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kickme/32/16525_2.png) [@KickMe](https://discourse.processing.org/u/KickMe)\
**Post date:** [August 12, 2022, 9:35pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/1 "2022-08-12T21:35:00Z")

</div>

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](https://discourse.processing.org/t/get-location-of-a-papplet-window/28039) 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](https://github.com/processing/processing4/wiki/Exorcising-AWT). 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.

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [August 13, 2022, 4:17pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/2 "2022-08-13T16:17:05Z")

</div>

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

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

```

These are the methods available:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/b/cb2cf88b27c8022a2aba05af59834950448a63a5.png)

---

<div class="post-metadata">

**Author:** ![KickMe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kickme/32/16525_2.png) [@KickMe](https://discourse.processing.org/u/KickMe)\
**Post date:** [September 1, 2022, 7:08pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/3 "2022-09-01T19:08:51Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![KickMe](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kickme/32/16525_2.png) [@KickMe](https://discourse.processing.org/u/KickMe)\
**Post date:** [September 1, 2022, 7:14pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/4 "2022-09-01T19:14:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [September 2, 2022, 9:41am UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/5 "2022-09-02T09:41:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [September 2, 2022, 5:27pm UTC](https://discourse.processing.org/t/multitouch-screen-handling-in-processing-4/38331/6 "2022-09-02T17:27:48Z")

</div>

> [@KickMe](#):
>
> 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\

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