Skip to content

Commit d57218e

Browse files
authored
Merge pull request #16 from dhalbert/fix_mouse_no_move
Fix Mouse bug introduced in 3.0.0
2 parents 167e101 + 2ad25fa commit d57218e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

adafruit_hid/mouse.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def __init__(self):
6060
# Do a no-op to test if HID device is ready.
6161
# If not, wait a bit and try once more.
6262
try:
63-
self.move(0, 0, 0)
63+
self._send_no_move()
6464
except OSError:
6565
time.sleep(1)
66-
self.move(0, 0, 0)
66+
self._send_no_move()
6767

6868
def press(self, buttons):
6969
"""Press the given mouse buttons.
@@ -80,7 +80,7 @@ def press(self, buttons):
8080
m.press(Mouse.LEFT_BUTTON | Mouse.RIGHT_BUTTON)
8181
"""
8282
self.report[0] |= buttons
83-
self.move(0, 0, 0)
83+
self._send_no_move()
8484

8585
def release(self, buttons):
8686
"""Release the given mouse buttons.
@@ -89,12 +89,12 @@ def release(self, buttons):
8989
``MIDDLE_BUTTON``, and ``RIGHT_BUTTON``.
9090
"""
9191
self.report[0] &= ~buttons
92-
self.move(0, 0, 0)
92+
self._send_no_move()
9393

9494
def release_all(self):
9595
"""Release all the mouse buttons."""
9696
self.report[0] = 0
97-
self.move(0, 0, 0)
97+
self._send_no_move()
9898

9999
def click(self, buttons):
100100
"""Press and release the given mouse buttons.
@@ -111,7 +111,6 @@ def click(self, buttons):
111111
m.click(Mouse.LEFT_BUTTON)
112112
m.click(Mouse.LEFT_BUTTON)
113113
"""
114-
115114
self.press(buttons)
116115
self.release(buttons)
117116

@@ -140,7 +139,6 @@ def move(self, x=0, y=0, wheel=0):
140139
# Roll the mouse wheel away from the user.
141140
m.move(wheel=1)
142141
"""
143-
144142
# Send multiple reports if necessary to move or scroll requested amounts.
145143
while x != 0 or y != 0 or wheel != 0:
146144
partial_x = self._limit(x)
@@ -154,6 +152,13 @@ def move(self, x=0, y=0, wheel=0):
154152
y -= partial_y
155153
wheel -= partial_wheel
156154

155+
def _send_no_move(self):
156+
"""Send a button-only report."""
157+
self.report[1] = 0
158+
self.report[2] = 0
159+
self.report[3] = 0
160+
self.hid_mouse.send_report(self.report)
161+
157162
@staticmethod
158163
def _limit(dist):
159164
return min(127, max(-127, dist))

0 commit comments

Comments
 (0)