Button on a touchscreen

Hi, I’m trying to create a drawing program that will work with a touch screen. Right now I can draw on the screen with a pen, but if I try to click a button on the screen my program won’t respond. I have to either swipe, or double tap for my program to work. All my code works well with a mouse. I use an if() statement and mousePressed for the buttons. I have tried mouseClicked() and mouseRealesed() and they have worked either the same way or worse. I was wondering if there were any touch commands for processing, or any java ones I could use. If anyone has the solution please help. Thanks! :slightly_smiling_face:

Please provide specs of your system. It might help, or provide a better lead.

Not an expert on this, but maybe the next links could be relevant.

https://docs.oracle.com/javase/8/javafx/events-tutorial/touch_events.htm
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/input/TouchEvent.html
https://stackoverflow.com/questions/23239239/separate-touch-from-mouse-event

There could be a bit of an issue with mouse events, and connecting to touch events, as Processing seems to define its own MouseEvent class. Not sure if this is a problem at the end but it is good to keep it in mid during the debugging process. For this, check Library Basics.

Kf

1 Like

Sorry I couldn’t respond sooner,
I use windows 8.1 and processing 3.3.7 on a 2 in 1 laptop.
here is my code for the buttons:
void appBar() {
if (bar==true) {
noStroke();
//stroke(r, g, b);
//strokeWeight(10);
fill(150);
rect(0, 0, width, 100);
textAlign(CENTER, BOTTOM);
fill(0);
textSize(60);
text(“Aidan Land Ink”, width/2, 100);
fill(255, 0, 0);
rect(0, 0, 100, 100);
fill(0, 255, 0);
rect(100, 0, 100, 100);
fill(0, 0, 255);
rect(200, 0, 100, 100);
fill(0);
rect(300, 0, 100, 100);
if (mouseX<400&&mouseY<100&&mousePressed) {
r=red(get(mouseX, mouseY));
g=green(get(mouseX, mouseY));
b=blue(get(mouseX, mouseY));
}
if (e==false) {
fill(r, g, b);
} else {
fill(255);
}
if (s==true) {
ellipse(450, 50, 100, 100);
} else {
ellipse(450, 50, 50, 50);
}
if (mouseY<100&&mouseX>400&&mouseX<500&&mousePressed) {
s=!s;
delay(100);
}

fill(255);
ellipse(550, 50, 100, 100);
if (mouseY<100&&mouseX>500&&mouseX<600&&mousePressed) {
  e=!e;
  delay(100);
}
if (mouseX>600&&mouseX<displayWidth-100&&mouseY<100&&red(get(mouseX, mouseY))==0&&mousePressed) {
  launch(path[0]);
  save("data\\saved.png");
  exit();
}

}else{
noStroke();
fill(255);
rect(0,0,width,100);
}
}

I then call the appbar() command in my draw loop.
I did look at the links in your reply and the TouchEvent looked like something that would work, but I couldn’t figure out how to use them in processing.(I’m no expert either)
I hope some of this helps.