【问题标题】:the mouse moves quickly when i move right当我向右移动时鼠标快速移动
【发布时间】:2022-12-09 17:23:05
【问题描述】:

我将 Arduino 与主机护罩一起使用,并使用此代码使我的鼠标连接到主机护罩,但是当我将鼠标向右拖动时,它移动得非常快,只有当我将鼠标向右移动时才会发生这种情况,其他方向正常,请问是什么?

#include <Mouse.h>

#include <Wire.h>

#include <SPI.h>

#include <usbhub.h>

USB Usb;
USBHub Hub( & Usb);

byte bf[2];

#include <hidboot.h>

HIDBoot < USB_HID_PROTOCOL_MOUSE > HidMouse( & Usb);

String myString;
int j = 0;
int c = 0;
int e = 0;
int lmb = 0;
int rmb = 0;
int mmb = 0;
int dx;
int dy;
int arr[2];
int arrv[8];

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)

{

  dx = mi -> dX;

  dy = mi -> dY;

};

void MouseRptParser::OnLeftButtonUp(MOUSEINFO * mi)

{

  lmb = 0;

};

void MouseRptParser::OnLeftButtonDown(MOUSEINFO * mi)

{

  lmb = 1;

};

void MouseRptParser::OnRightButtonUp(MOUSEINFO * mi)

{

  rmb = 0;

};

void MouseRptParser::OnRightButtonDown(MOUSEINFO * mi)

{

  rmb = 1;

};

void MouseRptParser::OnMiddleButtonUp(MOUSEINFO * mi)

{

  mmb = 0;

};

void MouseRptParser::OnMiddleButtonDown(MOUSEINFO * mi)

{

  mmb = 1;

};

MouseRptParser Prs;

void setup() {

  delay(5000);
  Mouse.begin();
  Serial.begin(115200);
  Serial.setTimeout(1);

  Usb.Init();
  HidMouse.SetReportParser(0, & Prs);
}

void loop() {
  dx = 0;

  dy = 0;

  j = 0;

  c = 0;

  e = 0;

  Usb.Task();

  //Clicking 

  if (lmb == 0) {

    Mouse.release(MOUSE_LEFT);

  } else if (lmb == 1) {

    Mouse.press(MOUSE_LEFT);

  }

  if (rmb == 0) {

    Mouse.release(MOUSE_RIGHT);

  } else if (rmb == 1) {

    Mouse.press(MOUSE_RIGHT);

  }

  if (mmb == 0) {

    Mouse.release(MOUSE_MIDDLE);

  } else if (mmb == 1) {

    Mouse.press(MOUSE_MIDDLE);

  }
  if (Serial.available() > 0) {
    Serial.readBytes(bf, 2);

    Mouse.move(bf[0], bf[1], 0);

  } else {

    Mouse.move(dx, dy);

  }
}

我试图更改库,但问题仍然存在

【问题讨论】:

  • 只有当我将鼠标向右移动时移动速度非常快,对于其他方向则没有,当我向下移动时鼠标正常向下移动,当我向右移动时似乎灵敏度很高并且鼠标移动迅速超出正常范围

标签: arduino


【解决方案1】:

你能解决这个问题吗?我也面临着。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2021-09-15
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多