Skip to content

Commit

Permalink
Merge pull request #9 from Sigafoos/examples
Browse files Browse the repository at this point in the history
Added examples for keyboard shortcuts and a mouse scrollwheel
  • Loading branch information
ladyada authored Jan 9, 2018
2 parents 1fdb20b + 75f14ef commit 48b707a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/keyboard_shortcuts.py
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)
27 changes: 27 additions & 0 deletions examples/scroll.py
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)

0 comments on commit 48b707a

Please sign in to comment.