# Recognize a double tap

**URL:** https://discourse.processing.org/t/recognize-a-double-tap/27536
**Category:** Processing for Android
**Created:** [February 1, 2021, 8:13pm UTC](https://discourse.processing.org/t/recognize-a-double-tap/27536 "2021-02-01T20:13:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [February 1, 2021, 8:13pm UTC](https://discourse.processing.org/t/recognize-a-double-tap/27536/1 "2021-02-01T20:13:38Z")

</div>

Hey, I wanted to ask how to recognize a double tap on the cell phone.  
There is MouseEvent.getCount () on the PC … but it doesn’t work on the mobile phone …

thanks in advance 🙂

---

<div class="post-metadata">

### Author: ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)
#### Post date: [February 1, 2021, 10:49pm UTC](https://discourse.processing.org/t/recognize-a-double-tap/27536/2 "2021-02-01T22:49:19Z")

</div>

I’m sure there is a built in function for this, however here is something I coded

```auto
int counter = 0;
boolean mdown, inc, mdown2;

void setup() {
  
}

void draw() {
  
  doubleClick() ;
  
  
  if(mdown2) {
    background(255);
  }
  
  
 // fill(255,0,0);
 // text(counter,10,10);
}

void doubleClick() {
  if( mousePressed&&counter == 0 &&! mdown){
   
    mdown = true;
    inc = true;
  }
  
  if(counter==0){
    background(0);
  }
  
  if(! mousePressed &&counter>100){
   counter = 0;
    
  }
  if(inc){
    background(0, 0,255);
    if(! mdown&&! mousePressed) {
      counter++;
    }
    
    if(counter>100){
      counter=0;
      inc = false;
    }
  }
  
  if(inc &&mousePressed&&! mdown) {
    
    mdown2 = true;
  }
  
  if(inc &&! mousePressed&& mdown2) {
    inc = false;
    counter = 0;
    mdown2 = false;
  }
  
  if(! mousePressed) {
    mdown = false;
    //ifinc = false;
  }
}

```

You could make doubleClick return mdown2 if necessary.

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [February 2, 2021, 12:34pm UTC](https://discourse.processing.org/t/recognize-a-double-tap/27536/3 "2021-02-02T12:34:24Z")

</div>

here is a function for mousePressed on Java mode (I don’t know if that is what you want but still, I’m posting it anyway)

```auto
int wait = 200,lastTime = -wait;
void setup() {} void draw() {}
void mousePressed() {
  if(lastTime + wait > millis()) {
    println("Double pressed",millis());
  } else {
    lastTime = millis();
  }
}

```

Explanation:  
`int wait` tells you the delay between clicks that is still acceptable as double click,  
`lastTime` registers the last mouse click millisecond. It is set to -wait, so it doesn’t register the first click  
in `void mousePressed() ` you first check if it is the second click in allowed timespan (`wait` milliseconds)  
if it is, it says: “Double pressed” [current runtime in milliseconds]. If it isn’t in allowed time it sets the last click to current time.

---

<div class="post-metadata">

### Author: ![Flolo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/flolo/32/13874_2.png) [@Flolo](https://discourse.processing.org/u/Flolo)
#### Post date: [February 2, 2021, 1:14pm UTC](https://discourse.processing.org/t/recognize-a-double-tap/27536/4 "2021-02-02T13:14:08Z")

</div>

Thanks, that helped me a lot.
