# Touchscreen Question

**URL:** https://discourse.processing.org/t/touchscreen-question/15405
**Category:** Coding Questions
**Created:** [November 11, 2019, 3:46pm UTC](https://discourse.processing.org/t/touchscreen-question/15405 "2019-11-11T15:46:45Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 11, 2019, 3:46pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/1 "2019-11-11T15:46:45Z")

</div>

I haave written a programm, in which you can click buttons, and a text will appear. Now, I have to know, if MousePressed() works on a touchscreen monitor, that means you dont click the mouse, but you tap the screen.  
@kll  
@Chrisir

---

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 11, 2019, 4:25pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/2 "2019-11-11T16:25:40Z")

</div>

Yes, it should work the same. I use Processing‘s IOS version, and mousePressed detects Touch input, so it should work the same for you.

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 11, 2019, 4:30pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/3 "2019-11-11T16:30:08Z")

</div>

I really hope so, thank you

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [November 11, 2019, 4:40pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/4 "2019-11-11T16:40:14Z")

</div>

I have a touchscreen laptop. If you want, I can test some code for you.

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 11, 2019, 6:29pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/5 "2019-11-11T18:29:43Z")

</div>

oh that would be really nice

```auto
int state = 0;

int x1=100, y1=100, w1=250, h1=250; //Button oben links
int x2=1570, y2=100, w2=250, h2=250; //Button oben rechts
int x3=100, y3=730, w3=250, h3=250; //Button unten links
int x4=1570, y4=730, w4=250, h4=250; //Button unten rechts

int x5=80, y5=870, w5=250, h5=100; // Button zurück

void draw_4_button() { // _______ stat 0 only
  if ( over(x1, y1, w1, h1) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x1, y1, w1, h1);
  if ( over(x2, y2, w2, h2) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x2, y2, w2, h2);
  if ( over(x3, y3, w3, h3) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x3, y3, w3, h3);
  if ( over(x4, y4, w4, h4) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x4, y4, w4, h4);
}

void draw_zurueck_button() { //_ state 1,2,3
  if ( over(x5, y5, w5, h5) ) stroke(200, 0, 0); 
  else stroke(0);
  rect(x5, y5, w5, h5);
}

void setup() {
  fullScreen();
  //size(1920, 1080);
  fill(0, 0, 200);
  strokeWeight(10);
}

void draw() {
  background(200, 100, 200);
  if ( state == 0 ) draw_4_buttons();
  if ( state == 1 ) draw_back_button_and_some_text1();
  if ( state == 2 ) draw_back_button_and_some_text2();
  if ( state == 3 ) draw_back_button_and_some_text3();
  if ( state == 4 ) draw_back_button_and_some_text4();
}

void mousePressed() {
  if ( state == 0 ) {
    if ( over(x1, y1, w1, h1) ) state = 1;
    if ( over(x2, y2, w2, h2) ) state = 2;
    if ( over(x3, y3, w3, h3) ) state = 3;
    if ( over(x4, y4, w4, h4) ) state = 4;
  } else {
    if ( over(x5, y5, w5, h5) ) state = 0;
  }
}

void draw_4_buttons() {
  draw_4_button();
}

void draw_back_button_and_some_text1() {
  text("some text page1 ", 20, 20);
  draw_zurueck_button();
}

void draw_back_button_and_some_text2() {
  text("some text page2 ", 20, 20);
  draw_zurueck_button();
}

void draw_back_button_and_some_text3() {
  text("some text page3 ", 20, 20);
  draw_zurueck_button();
}

void draw_back_button_and_some_text4() {
  text("some text page4 ", 20, 20);
  draw_zurueck_button();
}

boolean over(int x, int y, int w, int h) {
  return ( mouseX > x & mouseX < x + w &&
    mouseY > y & mouseY < y + h ) ;
}

```

@Tiemen

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [November 11, 2019, 8:47pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/6 "2019-11-11T20:47:21Z")

</div>

It works fine on my Lenovo Yoga. If I keep my finger on the screen and move over the buttons they get a red outline (hover effect), and when I release my finger it counts as a click.

Keep in mind that once I’ve clicked somewhere on the screen, the mouse cursor is still there but it’s turned invisble by Windows.This means that once I’ve pressed the back button, the button in the left corner is hovered since my invisible cursor is still placed there. The moment I touch the screen elsewhere the red hover effect vanishes.

If you need anything else tested just let me know 🙂

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 12, 2019, 8:58am UTC](https://discourse.processing.org/t/touchscreen-question/15405/7 "2019-11-12T08:58:06Z")

</div>

no thats fine thank you very much 😃

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 12, 2019, 9:08am UTC](https://discourse.processing.org/t/touchscreen-question/15405/8 "2019-11-12T09:08:24Z")

</div>

could you check already what hardware that would be? you have to run with?

> a monitor with

- a HDMI input
- USB output ( from like capacitive touch screen )

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 12, 2019, 9:59am UTC](https://discourse.processing.org/t/touchscreen-question/15405/9 "2019-11-12T09:59:45Z")

</div>

it is like a normal screen, but it has touch. Also the input is VGA

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 12, 2019, 10:09am UTC](https://discourse.processing.org/t/touchscreen-question/15405/10 "2019-11-12T10:09:54Z")

</div>

you can touch any monitor…  
but if it has a touch screen it still have to give  
that TOUCH EVENT back to the computer ( emulating a mouse ? THATs the question )  
( and can not do by a VGA cable i think )

* * *

i not understand what is the problem to ask the people what told you  
about that you have to use that equipment.  
( or do a pre test on it )

---

<div class="post-metadata">

### Author: ![Ladan](https://avatars.discourse-cdn.com/v4/letter/l/dbc845/32.png) [@Ladan](https://discourse.processing.org/u/Ladan)
#### Post date: [November 12, 2019, 3:11pm UTC](https://discourse.processing.org/t/touchscreen-question/15405/11 "2019-11-12T15:11:57Z")

</div>

> [@kll](#):
>
> at TOUCH EVENT back to the computer ( emulating a mouse ? THATs the question )

i think, that it is emulating a mouse, but idk.
