Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import time
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import board
import digitalio
kbd = Keyboard()
# define buttons. these can be any physical switches/buttons, but the values
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
swap = digitalio.DigitalInOut(board.D4)
swap.direction = digitalio.Direction.INPUT
swap.pull = digitalio.Pull.DOWN
search = digitalio.DigitalInOut(board.D5)
search.direction = digitalio.Direction.INPUT
search.pull = digitalio.Pull.DOWN
while True:
# press ALT+TAB to swap windows
if swap.value:
kbd.send(Keycode.ALT, Keycode.TAB)
# press CTRL+K, which in a web browser will open the search dialog
elif search.value:
kbd.send(Keycode.CONTROL, Keycode.K)
time.sleep(0.1)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import time
from adafruit_hid.mouse import Mouse
import board
import digitalio
mouse = Mouse()
# define buttons. these can be any physical switches/buttons, but the values
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
up = digitalio.DigitalInOut(board.D4)
up.direction = digitalio.Direction.INPUT
up.pull = digitalio.Pull.DOWN
down = digitalio.DigitalInOut(board.D5)
down.direction = digitalio.Direction.INPUT
down.pull = digitalio.Pull.DOWN
while True:
# scroll up one unit (varies with host/OS)
if up.value:
mouse.move(wheel=1)
# scroll down one unit (varies with host/OS)
elif down.value:
mouse.move(wheel=-1)
time.sleep(0.1)
|