File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ # SPDX-FileCopyrightText: 2022 Ruiz Bros for Adafruit Industries
2+ # SPDX-License-Identifier: MIT
3+
4+ import time
5+ import digitalio
6+ import board
7+ import usb_hid
8+ from adafruit_hid .keyboard import Keyboard
9+ from adafruit_hid .keycode import Keycode
10+
11+ # The button pins we'll use, each will have an internal pullup
12+ buttonpins = [board .D0 ]
13+
14+ # The keycode sent for each button, will be paired with a control key
15+ buttonkeys = [
16+ Keycode .SPACE # Space
17+ ]
18+
19+ keyboard = Keyboard (usb_hid .devices )
20+
21+ # our array of button objects
22+ buttons = []
23+
24+ # make all pin objects, make them inputs w/pullups
25+ for pin in buttonpins :
26+ button = digitalio .DigitalInOut (pin )
27+ button .direction = digitalio .Direction .INPUT
28+ button .pull = digitalio .Pull .UP
29+ buttons .append (button )
30+
31+ print ("Waiting for button presses" )
32+
33+ while True :
34+ # check each button
35+ for button in buttons :
36+ if not button .value : # pressed?
37+ i = buttons .index (button )
38+
39+ print ("Button #%d Pressed" % i )
40+
41+ while not button .value :
42+ pass # wait for it to be released!
43+ # type the keycode!
44+ k = buttonkeys [i ] # get the corresp. keycode
45+ keyboard .press (k )
46+ keyboard .release_all ()
47+ time .sleep (0.01 )
You can’t perform that action at this time.
0 commit comments