Mouse.IsPressed not working

Hi,

I have an Arduino Leonardo and a USB host shield.

I'm trying to have a Serial.println while the left click is pressed but it seems not working. Here is the snippet:

void loop()
{
  Usb.Task();

  if(Mouse.isPressed())
  {
    Serial.println("Pressed");
  }
}

Can I have a help with that?

Thanks, Bruno Arruda

Welcome to the Forum. Start by reading the stickies at the top of every section which tell you how to post on the forum and what information to provide. This will help others to help you get the answer you need. |500x238 In particular make sure that your code is inside code tags. You can edit a post to include them. If the code is too big attach it as a file or create a smaller code that is able to compile and incudes the problem (do not use snippets). It is preferable if you auto format your code before loading it as this will make it easier to read (use CTRL T in the IDE). |500x135 Schematics are often useful. You can draw them using a pencil and paper, or use an online tool and then post a picture of it. To post a picture upload it to an image hosting site and then put the link between image tags |500x138 If you do these simple things you will get Karma and are much more likely to get the answers you are looking for.

(deleted)

spycatcher2k: You cannot read the mouse from a computer using that library!

Thanks for the reply.

Which library can I use?

(deleted)

The "usb.Task()" function is a feature of the USBhost library that only works on an Arduino DUE. https://www.arduino.cc/en/Reference/USBHost

If you want to connect a USB mouse to an Arduino Leonardo I think you need to add a "USB Host Shield" and the library for it.

johnwasser: The "usb.Task()" function is a feature of the USBhost library that only works on an Arduino DUE. https://www.arduino.cc/en/Reference/USBHost

If you want to connect a USB mouse to an Arduino Leonardo I think you need to add a "USB Host Shield" and the library for it.

Thanks for your answer johnwasser.

I achieved what I was trying to do.

I'm trying to slow the speed of Y while dragging the mouse down. Using the https://github.com/felis/USB_Host_Shield_2.0 library, I can have the events, etc.

The snippet I have for it:

void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
    Serial.print("dx=");
    Serial.print(mi->dX, DEC);
    Serial.print(" dy=");
    Serial.println(mi->dZ);

  if (pressed)
  {
    if (mi->dZ > 0)
    {     
      mi->dZ = 1;
    }
  }
};

Using conventional mice, I can hold the speed while dragging but I have Zowie mouse configured for 400 dpi. Still, the sensitivity of this mouse is so low, which means if I set the velocity 1 is not enough to decrease for the desired speed while dragging.

You can see I set dZ because I had to change the library; the Y is configured under a different buffer position.

void MouseRptParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf)
{
  MouseReportParser::Parse(hid, is_rpt_id, len, buf);

  if (len > 2) {
    uint8_t mouseRpt[4];
    mouseRpt[0] = buf[0];
    mouseRpt[1] = buf[1];
    mouseRpt[2] = buf[3];
    if (len > 3) {
      mouseRpt[3] = buf[5];
    }
    else {
      mouseRpt[3] = 0;
    }

        Serial.print(buf[0]);
        Serial.print("\t");
        Serial.print(buf[1]);
        Serial.print("\t");
        Serial.print(buf[2]);
        Serial.print("\t");
        Serial.print(buf[3]);
        Serial.print("\t");
        Serial.print(buf[4]);
        Serial.print("\t");
        Serial.print(buf[5]);
        Serial.print("\t");
        Serial.print(buf[6]);
        Serial.print("\t");
        Serial.print(buf[7]);
        Serial.print("\t");
        Serial.print(buf[11]);
        Serial.print("\t");
        Serial.print(buf[12]);
        Serial.print("\t");
        Serial.print(buf[13]);
        Serial.println();
        

    HID().SendReport(1, mouseRpt, sizeof(mouseRpt));
  }
}

The result:

|500x291

But the Y expects an int, and as mentioned 1 is too high for 400 dpi, I was wondering some double conversion to have 1 split in half, but the library doesn't accept that.

The question is, while the native uses this buffer index to represent Y, is it possible to find out where is the secondary index position in the buffer, which represents the decimal for the velocity?

Thanks, Bruno Arruda