# touchEnded() clicks twice

**URL:** https://discourse.processing.org/t/touchended-clicks-twice/9263
**Category:** Coding Questions
**Created:** [March 13, 2019, 12:35pm UTC](https://discourse.processing.org/t/touchended-clicks-twice/9263 "2019-03-13T12:35:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![antocreo](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@antocreo](https://discourse.processing.org/u/antocreo)
#### Post date: [March 13, 2019, 12:35pm UTC](https://discourse.processing.org/t/touchended-clicks-twice/9263/1 "2019-03-13T12:35:27Z")

</div>

Hi everyone,  
I am having some problem with `touchEnded()` function.  
I am using it to switch from a case to another and it works fine with the mouse on laptop.  
However, if I use a tablet it seems that the touch lasts longer as there was a lag between the touch and the end of the touch. Or it’s like the touch happened twice.

For example if I click in (xpos, ypos) and I am in case1, when it switches on case2 the touch is still active in the same position and it messes up with the things happening in the second case.

I am trying to understand what could be wrong but I can’t. The mouse click works well, the touch doesn’t.

here is a short version of the code. I have already tried to avoid the first conditional `(mouseButton===LEFT)` but the problems is still there.

Any idea anyone on what may be going on?

Thanks!

```auto
if(mouseButton === LEFT){
		switch(pages){

			case 'one':

				//code here
				pages = 'two';

			break;

			case 'two':
				//code here
				pages = 'three';

			break;
}
}

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [March 14, 2019, 5:45am UTC](https://discourse.processing.org/t/touchended-clicks-twice/9263/2 "2019-03-14T05:45:45Z")

</div>

Check these next links as they can provide some suggestions that could help in your current isssue:

> [https://forum.processing.org/two/discussion/19344/mouse-and-touch-events-fire-twice](https://forum.processing.org/two/discussion/19344/mouse-and-touch-events-fire-twice)

> [mousePressed and touchStarted broken in chrome mobile · Issue #1815 · processing/p5.js · GitHub](https://github.com/processing/p5.js/issues/1815)

> [touchEnded() fires "evt is undefined" - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/20372/touchended-fires-evt-is-undefined)

Where are you calling this function from? It is better to provide a minimum version of your code demonstrating your problem.

Kf

---

<div class="post-metadata">

### Author: ![antocreo](https://avatars.discourse-cdn.com/v4/letter/a/ad7895/32.png) [@antocreo](https://discourse.processing.org/u/antocreo)
#### Post date: [March 19, 2019, 12:14pm UTC](https://discourse.processing.org/t/touchended-clicks-twice/9263/3 "2019-03-19T12:14:09Z")

</div>

Hi, thanks for replying. I’ve read your links and I started exploring from there.  
Apparently the problem is in the browser that I use.  
Chrome should read both mouse and touch and give priority to whatever device is used but Firefox or other browsers don’t. However, I couldn’t find a way to fix it even following the examples provided.  
At the moment I am thinking to avoid touch devices because I don’t have much time but I would like to get back to it later.

I will post some code that makes sense as soon as I can 🙂

Cheers
