# TouchStarted() problem with mobile

**URL:** <https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164>\
**Category:** p5.js\
**Created:** [July 30, 2022, 1:52pm UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164 "2022-07-30T13:52:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FredGuillot](https://avatars.discourse-cdn.com/v4/letter/f/6f9a4e/32.png) [@FredGuillot](https://discourse.processing.org/u/FredGuillot)\
**Post date:** [July 30, 2022, 1:52pm UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164/1 "2022-07-30T13:52:32Z")

</div>

Hello, I have a sketch where I use the touchStarted() function, and it does not work with a mobile device (i.e.: nothing happen when I’m touching the screen).

NOTE: when I run the same script with a compute, it works well - it’s just the mobile devices that seems to have a problem.

Any proposed workaround for that ?

Thanks !

Fred.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 30, 2022, 2:18pm UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164/2 "2022-07-30T14:18:34Z")

</div>

HI @FredGuillot,

did you notice that ?

> Browsers may have different default behaviors attached to various touch events. To prevent any default behavior for this event, add “return false” to the end of the method

see touchStarted:

> **[reference | p5.js](https://p5js.org/reference/#/p5/touchStarted)**
>
> p5.js a JS client-side library for creating graphic and interactive experiences, based on the core principles of Processing.

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![FredGuillot](https://avatars.discourse-cdn.com/v4/letter/f/6f9a4e/32.png) [@FredGuillot](https://discourse.processing.org/u/FredGuillot)\
**Post date:** [July 30, 2022, 3:48pm UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164/3 "2022-07-30T15:48:40Z")

</div>

Thanks for your fast reply ! Yes, I just saw thing this morning and I try that but it still not working …

Could it be because I have both a mousePressed and a touchStarted statements in my sketch (my goal with this is to handle both computer and mobile experience)?

Also, I tried to switch mouseX/mouseY by touchX/ touchY in the script with no success …

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [July 30, 2022, 3:57pm UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164/4 "2022-07-30T15:57:45Z")

</div>

Hi @FredGuillot,

> The touchStarted() function is called once after every time a touch is registered. If no [touchStarted()](https://p5js.org/reference/#/p5/touchStarted) function is defined, the [mousePressed()](https://p5js.org/reference/#/p5/mousePressed) function will be called instead if it is defined.

As suggested here you can remove the touchStarted and just use mousePressed for both …  
Afterwards use mouseX and mouseY to get the location. On my mobile it works …

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![FredGuillot](https://avatars.discourse-cdn.com/v4/letter/f/6f9a4e/32.png) [@FredGuillot](https://discourse.processing.org/u/FredGuillot)\
**Post date:** [July 31, 2022, 2:14am UTC](https://discourse.processing.org/t/touchstarted-problem-with-mobile/38164/5 "2022-07-31T02:14:15Z")

</div>

Hey, it was the issue ! It’s working now ! Thank you so much for your great help !

Cheers !
