How to make a push button make double clicks and a single click like on a mouse?

I am making a mouse using push buttons. I want to record double clicks and single clicks separately but am not bein able to. Either it shows a single click or a double click. Could someone help me with an example code or a tutorial somewhere? Greatly appreciated.

This is my code so far..
int ck = 13;
int t;
int i;

void setup() {
  // put your setup code here, to run once:
  digitalWrite(ck, HIGH);
  t = 0;
  i = 0;
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(ck, HIGH);
  if (digitalRead(ck) == LOW) {
    digitalWrite(ck, HIGH);
    delay(150);
while(i < 300) {
      digitalWrite(ck, HIGH);
      i++;
      if (digitalRead(ck) == LOW) {
        t = 1;
        break;
      }
      delay(3);
    }
    if (t == 0) {
      Mouse.click(MOUSE_LEFT);
      delay(1500);
    }
    else if (t == 1) {
      Mouse.click(MOUSE_LEFT);
      Mouse.click(MOUSE_LEFT);
      delay(1500);
    }
  }
}

plouc2 years ago

as a general idea, you will have to detect one or more edge, in a certain lap of time. As I understand you use an Arduino and a library that allow just calling mouse.click to click. Then detecting one edge is enough. Do a polling fast enough to catch a second edge and it should be good. Edge detection is done by polling input in a regular basis. When the state recorded is different than the precedent one, you got an edge. Looking at your code, what is the purpose of writing a state on the pushbutton input?

seandogue2 years ago

I'd think you would need to hook into a literal "mouse.doubleClick" event, rather than attempting to use a pair of sequential "mouse.click"s. Maybe arduino offers some library of mouse events...look there for a doubleclick

bwrussell2 years ago

I think there might software out there that already does this. I don't have anything more than that, sorry. Google probably can guide you.