adafruit / Adafruit_CircuitPython_HID

USB Human Interface Device drivers.
MIT License
364 stars 106 forks source link

Possible error in Mouse movement library. #98

Closed xgpt closed 2 years ago

xgpt commented 2 years ago
#yields only behavior in positive direction

VAR1 = -10
VAR2 = 10

def up():
    mouse.move(y=VAR1)
    time.sleep(1)

def down():
    mouse.move(y=VAR2)
    time.sleep(1)
#yields behavior in both directions

VAR1 = -10
VAR2 = 10

def up():
    mouse.move(y=-VAR1)
    time.sleep(1)

def down():
    mouse.move(y=VAR2)
    time.sleep(1)

Why?

xgpt commented 2 years ago

https://github.com/adafruit/Adafruit_CircuitPython_HID/blob/47cc91474823677218239b5b37901590755cac4c/adafruit_hid/mouse.py

        """
        # Send multiple reports if necessary to move or scroll requested amounts.
        while x != 0 or y != 0 or wheel != 0:
            partial_x = self._limit(x)
            partial_y = self._limit(y)
            partial_wheel = self._limit(wheel)
            self.report[1] = partial_x & 0xFF
            self.report[2] = partial_y & 0xFF
            self.report[3] = partial_wheel & 0xFF
            self._mouse_device.send_report(self.report)
            x -= partial_x
            y -= partial_y
            wheel -= partial_wheel

    def _send_no_move(self) -> None:
        """Send a button-only report."""
        self.report[1] = 0
        self.report[2] = 0
        self.report[3] = 0
        self._mouse_device.send_report(self.report)

    @staticmethod
    def _limit(dist: int) -> int:
        return min(127, max(-127, dist))

I'm too n00b to understand what that block of _limit is all about, or if -= and a negative variable would do something weird...idk.

xgpt commented 2 years ago

I made a mistake. Library works great!