-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Sigafoos/examples
Added examples for keyboard shortcuts and a mouse scrollwheel
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
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.press(Keycode.ALT, Keycode.TAB) | ||
kbd.release_all() | ||
|
||
# press CTRL+K, which in a web browser will open the search dialog | ||
elif search.value: | ||
kbd.press(Keycode.CONTROL, Keycode.K) | ||
kbd.release_all() | ||
|
||
time.sleep(0.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |