Skip to content

Commit 48b707a

Browse files
authored
Merge pull request #9 from Sigafoos/examples
Added examples for keyboard shortcuts and a mouse scrollwheel
2 parents 1fdb20b + 75f14ef commit 48b707a

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

examples/keyboard_shortcuts.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import time
2+
from adafruit_hid.keyboard import Keyboard
3+
from adafruit_hid.keycode import Keycode
4+
import board
5+
import digitalio
6+
7+
kbd = Keyboard()
8+
9+
# define buttons. these can be any physical switches/buttons, but the values
10+
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
11+
swap = digitalio.DigitalInOut(board.D4)
12+
swap.direction = digitalio.Direction.INPUT
13+
swap.pull = digitalio.Pull.DOWN
14+
15+
search = digitalio.DigitalInOut(board.D5)
16+
search.direction = digitalio.Direction.INPUT
17+
search.pull = digitalio.Pull.DOWN
18+
19+
while True:
20+
# press ALT+TAB to swap windows
21+
if swap.value:
22+
kbd.press(Keycode.ALT, Keycode.TAB)
23+
kbd.release_all()
24+
25+
# press CTRL+K, which in a web browser will open the search dialog
26+
elif search.value:
27+
kbd.press(Keycode.CONTROL, Keycode.K)
28+
kbd.release_all()
29+
30+
time.sleep(0.1)

examples/scroll.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import time
2+
from adafruit_hid.mouse import Mouse
3+
import board
4+
import digitalio
5+
6+
mouse = Mouse()
7+
8+
# define buttons. these can be any physical switches/buttons, but the values
9+
# here work out-of-the-box with a CircuitPlayground Express' A and B buttons.
10+
up = digitalio.DigitalInOut(board.D4)
11+
up.direction = digitalio.Direction.INPUT
12+
up.pull = digitalio.Pull.DOWN
13+
14+
down = digitalio.DigitalInOut(board.D5)
15+
down.direction = digitalio.Direction.INPUT
16+
down.pull = digitalio.Pull.DOWN
17+
18+
while True:
19+
# scroll up one unit (varies with host/OS)
20+
if up.value:
21+
mouse.move(wheel=1)
22+
23+
# scroll down one unit (varies with host/OS)
24+
elif down.value:
25+
mouse.move(wheel=-1)
26+
27+
time.sleep(0.1)

0 commit comments

Comments
 (0)