Adafruit_Learning_System_Gu.../Make_It_A-Mouse/cpx-mouse-buttons/code.py
2022-02-23 14:08:26 -05:00

22 lines
600 B
Python

# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse
m = Mouse(usb_hid.devices)
while True:
if cpx.button_a:
m.press(Mouse.LEFT_BUTTON)
while cpx.button_a: # Wait for button A to be released
pass
m.release(Mouse.LEFT_BUTTON)
if cpx.button_b:
m.press(Mouse.RIGHT_BUTTON)
while cpx.button_b: # Wait for button B to be released
pass
m.release(Mouse.RIGHT_BUTTON)