@@ -60,10 +60,10 @@ def __init__(self):
60
60
# Do a no-op to test if HID device is ready.
61
61
# If not, wait a bit and try once more.
62
62
try :
63
- self .move ( 0 , 0 , 0 )
63
+ self ._send_no_move ( )
64
64
except OSError :
65
65
time .sleep (1 )
66
- self .move ( 0 , 0 , 0 )
66
+ self ._send_no_move ( )
67
67
68
68
def press (self , buttons ):
69
69
"""Press the given mouse buttons.
@@ -80,7 +80,7 @@ def press(self, buttons):
80
80
m.press(Mouse.LEFT_BUTTON | Mouse.RIGHT_BUTTON)
81
81
"""
82
82
self .report [0 ] |= buttons
83
- self .move ( 0 , 0 , 0 )
83
+ self ._send_no_move ( )
84
84
85
85
def release (self , buttons ):
86
86
"""Release the given mouse buttons.
@@ -89,12 +89,12 @@ def release(self, buttons):
89
89
``MIDDLE_BUTTON``, and ``RIGHT_BUTTON``.
90
90
"""
91
91
self .report [0 ] &= ~ buttons
92
- self .move ( 0 , 0 , 0 )
92
+ self ._send_no_move ( )
93
93
94
94
def release_all (self ):
95
95
"""Release all the mouse buttons."""
96
96
self .report [0 ] = 0
97
- self .move ( 0 , 0 , 0 )
97
+ self ._send_no_move ( )
98
98
99
99
def click (self , buttons ):
100
100
"""Press and release the given mouse buttons.
@@ -111,7 +111,6 @@ def click(self, buttons):
111
111
m.click(Mouse.LEFT_BUTTON)
112
112
m.click(Mouse.LEFT_BUTTON)
113
113
"""
114
-
115
114
self .press (buttons )
116
115
self .release (buttons )
117
116
@@ -140,7 +139,6 @@ def move(self, x=0, y=0, wheel=0):
140
139
# Roll the mouse wheel away from the user.
141
140
m.move(wheel=1)
142
141
"""
143
-
144
142
# Send multiple reports if necessary to move or scroll requested amounts.
145
143
while x != 0 or y != 0 or wheel != 0 :
146
144
partial_x = self ._limit (x )
@@ -154,6 +152,13 @@ def move(self, x=0, y=0, wheel=0):
154
152
y -= partial_y
155
153
wheel -= partial_wheel
156
154
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
+
157
162
@staticmethod
158
163
def _limit (dist ):
159
164
return min (127 , max (- 127 , dist ))
0 commit comments