# My solution for trigger events in iOS, Android and Desktop

**URL:** https://discourse.processing.org/t/my-solution-for-trigger-events-in-ios-android-and-desktop/24882
**Category:** p5.js
**Created:** [October 24, 2020, 10:18pm UTC](https://discourse.processing.org/t/my-solution-for-trigger-events-in-ios-android-and-desktop/24882 "2020-10-24T22:18:17Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![rvalla](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rvalla/32/10911_2.png) [@rvalla](https://discourse.processing.org/u/rvalla)
#### Post date: [October 24, 2020, 10:18pm UTC](https://discourse.processing.org/t/my-solution-for-trigger-events-in-ios-android-and-desktop/24882/1 "2020-10-24T22:18:17Z")

</div>

I fought all day looking for a way to trigger events which works in all browsers and systems. I was unexpected, but mousePressed() seems to not work in Safari in iOS if you define a doubleClicked() function.  
You could use mousePressed() but… In Android each touch in a button counts double…  
I share my solution here, may be is useful for someone.  
I simply block the second event in Android with avoiding consecutive clicks.

```auto
let lastclick;

function setup() {
   lastclick = 0;
}

function mousePressed() {
   if (500 < millis() - lastclick) {
      if (b1.contains(mouseX, mouseY)) {
         bp1 += 1;
         state += 1;
      } 
    lastclick = millis();
  }
}

```

I am testing this [here](https://rvalla.github.io/assets/testing/p5js/testing_ev.html).
