Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import digitalio
  2. from board import *
  3. import time
  4. from adafruit_hid.keyboard import Keyboard
  5. from adafruit_hid.keycode import Keycode
  6.  
  7. # A simple neat keyboard demo in circuitpython
  8. buttonpins = [D0]
  9.  
  10. # The keycode sent for each button, optionally can be paired with a control key
  11. buttonkeys = [44]
  12. controlkey = Keycode.LEFT_CONTROL
  13.  
  14. # the keyboard object!
  15. kbd = Keyboard()
  16.  
  17. # our array of button objects
  18. buttons = []
  19.  
  20. # make all pin objects, make them inputs w/pullups
  21. for pin in buttonpins:
  22. button = digitalio.DigitalInOut(pin)
  23. button.direction = digitalio.Direction.INPUT
  24. button.pull = digitalio.Pull.UP
  25. buttons.append(button)
  26.  
  27. print("Waiting for button presses")
  28.  
  29. while True:
  30. # check each button
  31. for button in buttons:
  32. if (not button.value): # pressed?
  33. i = buttons.index(button)
  34.  
  35. print("Button #%d Pressed" % i)
  36.  
  37. # type the keycode!
  38. k = buttonkeys[i] # get the corresp. keycode
  39. kbd.press(k)
  40. # Use this line for key combos kbd.press(k, controlkey)
  41. kbd.release_all()
  42.  
  43. while (not button.value):
  44. pass # wait for it to be released!
  45. time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement