Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mouse press and release not working correctly after move #1

Open
kapsa opened this issue Jun 6, 2024 · 0 comments
Open

mouse press and release not working correctly after move #1

kapsa opened this issue Jun 6, 2024 · 0 comments

Comments

@kapsa
Copy link

kapsa commented Jun 6, 2024

The press() and release() functions should send mouse coordinates in a report. To fix use:

diff --git a/absolute_mouse/__init__.py b/absolute_mouse/__init__.py
index c67a673..4cc7615 100644
--- a/absolute_mouse/__init__.py
+++ b/absolute_mouse/__init__.py
@@ -40,6 +40,8 @@ class Mouse:
     """Middle mouse button."""
 
     def __init__(self, devices):
+        self._x = 0
+        self._y = 0
         """Create a Mouse object that will send USB mouse HID reports.
 
         Devices can be a list of devices that includes a keyboard device or a keyboard device
@@ -141,15 +143,15 @@ class Mouse:
             wheel -= partial_wheel
 
         # Coordinates
-        x = self._limit_coord(x)
-        y = self._limit_coord(y)
+        self._x = self._limit_coord(x)
+        self._y = self._limit_coord(y)
         # HID reports use little endian
-        self.report[1:5] = struct.pack("<HH", x, y)
+        self.report[1:5] = struct.pack("<HH", self._x, self._y)
         self._mouse_device.send_report(self.report)
 
     def _send_no_move(self):
         """Send a button-only report."""
-        self.report[1:5] = b"\x00\x00\x00\x00"
+        self.report[1:5] = struct.pack("<HH", self._x, self._y)
         self._mouse_device.send_report(self.report)
 
     @staticmethod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant