How to add x1 and x2 button mouse logitech leonardo + usb shield

hello i'm new to arduino, i wanted to know how can i adhere the button x1 (back) and button x2, i made my code in the following way.

#include <hidboot.h>
#include <usbhub.h>
#include <Mouse.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>
byte bf[3];

class MouseRptParser : public MouseReportParser
{
protected:
void OnMouseMove (MOUSEINFO *mi);
void OnLeftButtonUp (MOUSEINFO *mi);
void OnLeftButtonDown (MOUSEINFO *mi);
void OnRightButtonUp (MOUSEINFO *mi);
void OnRightButtonDown (MOUSEINFO *mi);
void OnMiddleButtonUp (MOUSEINFO *mi);
void OnMiddleButtonDown (MOUSEINFO *mi);
};

void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
int x = (x + mi->dX);
int y = (y + mi->dY);
Mouse.move(x, y);
};

void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi)
{
Mouse.release(MOUSE_LEFT);
};
void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi)
{
Mouse.press(MOUSE_LEFT);
};
void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi)
{
Mouse.release(MOUSE_RIGHT);
};
void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi)
{
Mouse.press(MOUSE_RIGHT);
};
void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi)
{
Mouse.release(MOUSE_MIDDLE);
};
void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi)
{
Mouse.press(MOUSE_MIDDLE);
};

USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);

MouseRptParser Prs;

void setup()
{
Serial.begin( 115200 );
#if !defined(MIPSEL)
//while (!Serial);
#endif
Serial.println("Start");

if (Usb.Init() == -1)
    Serial.println("OSC did not start.");

delay( 200 );

HidMouse.SetReportParser(0, &Prs);
Mouse.begin();

}

void loop()
{
Usb.Task();

if (Serial.available() > 0) {
Serial.readBytes(bf, 3);
Mouse.move(bf[0], bf[1]);
Serial.read();
if(bf[2]==1){
Mouse.click(MOUSE_LEFT);
}
}
}

@robertwiki1, your topic has been moved to a more suitable section of the forum.

Please take some time to read How to get the best out of this forum. Next edit your post and add code tags to your code.

1 Like

The more easy and interesting, to helpers, You make Your posting the more and better help You get.