Recognize a double tap

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 :slight_smile:

1 Like

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

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.

1 Like

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)

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.

1 Like

Thanks, that helped me a lot.

1 Like