Good morning all, recently joined lurker and this is my first post. I recently bought a Pico RGB Keypad with plans to make a multilayer macro pad to have excel shortcuts on one layer and some other bits and pieces on other layers. I can’t get text strings to work OK but the second I add keyboard shortcuts (ctrl+shift+d) in the same or any layer and press the button it crashes and needs restarted. I am using the pmk-circuit payton 15 layer file, although the same thing happens on the three layer file as well, from the pimoroni github (pmk-circuitpython/hid-keypad-fifteen-layers.py at main · pimoroni/pmk-circuitpython · GitHub) and thoughts would be greatly appreciated.
Hi euanlowe, I also had the same idea with my keypad. I’ve extended a version of the github’s example to support sending a bunch of keys in a row. The code I used is as follows for sending inputs:
def press_keys(keys):
to_send = keys
# Macro handling
if isinstance(to_send,tuple) == True:
# Check if item in list to send is a combo or a single key
for i in range(len(to_send)):
if isinstance(to_send[i], int) == True:
keyboard.send(to_send[i])
if isinstance(to_send[i],set) == True:
keys_to_send = to_send[i]
keyboard.send(*keys_to_send)
if isinstance(to_send, set) == True: # Single Key Combo
keyboard.press(*to_send)
if isinstance(to_send, int) == True: # Single keys, currently only for Consumer Control
consumer_control.send(to_send)
It’s a bit of a mess, but it needs to check the type so that it doesn’t error out when sending the inputs
If you want to send codes, you would need to store the keys you need to send in an array, it even supports key combos like so:
excel_layer = {
1: (Keycode.ALT, Keycode.H, Keycode.J,Keycode.HOME,Keycode.RIGHT_ARROW,Keycode.RIGHT_ARROW,Keycode.ENTER)
# Other keys go here in the same style
}
If you want to call it, using the same style of calling in the While loop:
While True:
for k in layers[current_layer].keys():
key_press = layers[current_layer][k]
if keys[k].pressed:
key_press = layers[current_layer][k]
debounce = long_debounce
if not fired:
fired = True
press_keys(key_press)
This lets you send a string of inputs. It also supports sending key combos inside the function but you need to make sure that a key combo is placed in a set (curly braces {}) and the string of inputs are a tuple (normal curved brackets).