Skip to content

Commit d214ace

Browse files
authored
Merge pull request #11 from RetiredWizard/usbmousebtns
add pressed_btns class property
2 parents 1b3bee5 + 4d29ced commit d214ace

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

adafruit_usb_host_mouse.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def __init__(self, device, endpoint_address, tilegrid, was_attached, scale=1):
149149
"""The sensitivity of the mouse cursor. Larger values will make
150150
the mouse cursor move slower relative to physical mouse movement. Default is 1."""
151151

152+
self.pressed_btns = []
153+
"""List of buttons currently pressed (one or more of "left", "right", "middle")
154+
If there's no new mouse data (nothing changes) this property can be checked to see
155+
which buttons are currently pressed."""
156+
152157
self.display_size = (supervisor.runtime.display.width, supervisor.runtime.display.height)
153158

154159
@property
@@ -218,13 +223,13 @@ def update(self):
218223
),
219224
)
220225

221-
pressed_btns = []
226+
self.pressed_btns = []
222227
for i, button in enumerate(BUTTONS):
223228
# check if each button is pressed using bitwise AND shifted
224229
# to the appropriate index for this button
225230
if self.buffer[0] & (1 << i) != 0:
226231
# append the button name to the string to show if
227232
# it is being clicked.
228-
pressed_btns.append(button)
233+
self.pressed_btns.append(button)
229234

230-
return tuple(pressed_btns)
235+
return tuple(self.pressed_btns)

0 commit comments

Comments
 (0)