Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import digitalio
- from board import *
- import time
- from adafruit_hid.keyboard import Keyboard
- from adafruit_hid.keycode import Keycode
- # A simple neat keyboard demo in circuitpython
- buttonpins = [D0]
- # The keycode sent for each button, optionally can be paired with a control key
- buttonkeys = [44]
- controlkey = Keycode.LEFT_CONTROL
- # the keyboard object!
- kbd = Keyboard()
- # our array of button objects
- buttons = []
- # make all pin objects, make them inputs w/pullups
- for pin in buttonpins:
- button = digitalio.DigitalInOut(pin)
- button.direction = digitalio.Direction.INPUT
- button.pull = digitalio.Pull.UP
- buttons.append(button)
- print("Waiting for button presses")
- while True:
- # check each button
- for button in buttons:
- if (not button.value): # pressed?
- i = buttons.index(button)
- print("Button #%d Pressed" % i)
- # type the keycode!
- k = buttonkeys[i] # get the corresp. keycode
- kbd.press(k)
- # Use this line for key combos kbd.press(k, controlkey)
- kbd.release_all()
- while (not button.value):
- pass # wait for it to be released!
- time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement