0

I built a stream deck through which I make keyboard inputs with CircuitPython:

import time
import board
import digitalio
import usb_hid
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard import Keyboard

def press_windows_d():
    keyboard.send(Keycode.WINDOWS, Keycode.D)
    time.sleep(0.1)

def press_ctrl_alt_c():
    # Control + Alt + C opens VS Code
    keyboard.send(Keycode.CONTROL, Keycode.ALT, Keycode.C)
    time.sleep(0.1)

def press_windows_up():
    keyboard.send(Keycode.WINDOWS, Keycode.UP_ARROW)
    time.sleep(0.1)

#following methods are placeholder
def press_key_A():
    keyboard.send(Keycode.A)
    time.sleep(0.1)

def press_key_B():
    keyboard.send(Keycode.B)
    time.sleep(0.1)

def press_key_C():
    keyboard.send(Keycode.C)
    time.sleep(0.1)

btn1_pin = board.GP2
btn2_pin = board.GP4
btn3_pin = board.GP6
btn4_pin = board.GP8
btn5_pin = board.GP10
btn6_pin = board.GP12

btn1 = digitalio.DigitalInOut(btn1_pin)
btn1.direction = digitalio.Direction.INPUT
btn1.pull = digitalio.Pull.DOWN

btn2 = digitalio.DigitalInOut(btn2_pin)
btn2.direction = digitalio.Direction.INPUT
btn2.pull = digitalio.Pull.DOWN

btn3 = digitalio.DigitalInOut(btn3_pin)
btn3.direction = digitalio.Direction.INPUT
btn3.pull = digitalio.Pull.DOWN

btn4 = digitalio.DigitalInOut(btn4_pin)
btn4.direction = digitalio.Direction.INPUT
btn4.pull = digitalio.Pull.DOWN

btn5 = digitalio.DigitalInOut(btn5_pin)
btn5.direction = digitalio.Direction.INPUT
btn5.pull = digitalio.Pull.DOWN

btn6 = digitalio.DigitalInOut(btn6_pin)
btn6.direction = digitalio.Direction.INPUT
btn6.pull = digitalio.Pull.DOWN

keyboard = Keyboard(usb_hid.devices)

while True:
    if btn1.value:
        press_windows_d()
    if btn2.value:
        press_ctrl_alt_c()
    if btn3.value:
        press_windows_up()
    if btn4.value:
        press_key_A()
    if btn5.value:
        press_key_B()
    if btn6.value:
        press_key_C()
    time.sleep(0.1)

When I execute a key combination (such as the desktop shortcut) the other buttons no longer respond and the Raspberry Pi Pico has to be plugged in again. What is the reason for this? Writing method contents into the if statements did not change anything.

user4157124
  • 2,809
  • 13
  • 27
  • 42
  • There are several "strange" things in your code: you use "keyboard" in your def's without declaring it beforehand, and not declaring it "global" either. Then you wait 0.1s in each of your keyboard calls, and also at the end of your loop. And worst: what happens if you keep pressing a key? every 0.2 seconds the key combo is sent. – Peter I. Aug 01 '23 at 10:36

0 Answers0