Key combinations on keybow

Searched around found some related questions but most of the threads were stale of incomplete.

Is there method without directly accessing the GPIO pins to configure actions based on key combinations not just singe key states.

Some background:
I’m currently using the pimoroni keybow-python libraries on a pi zero and the 3 key keybow to make requests.get and calls to another pi zero then set the LEDs based on a second GET/POST on the release of the key. I have it mostly working for the 3 functions needed but would like to add a reset and shut off options via key 0&1 and 1&2 respectively. Looking at both keybow-firmware and keybow-python I do not see a method to do this in a reliable way.

Have a look at this and see if it helps.
Using macros and snippets with Keybow - Pimoroni Yarr-niversity

My guess would be creating some variables to store whether the keybow buttons are currently pressed.

This script seems to done something similar so may be of some help:

I don’t own a Keybow just so you know, I just know my way around the Pimoroni resources and try to help out when I can. ;)
There are quite a few Keybow owners so you may get somebody that knows chiming in at some point.

Thanks to both @alphanumeric and @major_tomm. Just re-read both the links and still do not see a way short of directly polling the pins in a separate process.

But it did get me thinking of an alternate option using some diodes to create logical switches, making my 3 key mini appear to be a 12 key keybow with 6 missing keys but going to hold off a while before I go down that path.

My assumption was that you’d be able to do something like this

zero_pressed = false
one_pressed = false
two_pressed = false

function handle_key_00(pressed)
    zero_pressed = pressed
    if pressed and one_pressed then
        -- reset
    elseif pressed then
        -- do A

function handle_key_01(pressed)
    one_pressed = pressed
    if pressed and zero_pressed then
        -- reset
    elseif pressed and two_pressed then
        -- shutdown
    elseif pressed then
        -- do B

function handle_key_02(pressed)
    two_pressed = pressed
    if pressed and one_pressed then
        -- shutdown
    elseif pressed then
        -- do C

But it’s probably further complicated by the fact you’re doing actions on press and release.

Edit: Apologies for the Lua, I now notice you mention the python-library but the concept should be the same.

Looking further into the python library itself it just seems to use the regular RPi.GPIO to assign events to the pins.

Looking at the API, it should just be a matter of doing: GPIO.input(channel) to poll the current state of a pin, with the pin numbers defined by MINI earlier in the file.

I have a functional working concept, it is dirty but it works for the most part. So far the biggest leap has been the when taking to a coworker about the best way to do a lookup table in python was not to but treat the keys as binary registers. Not sure if I will look at using the API for just controlling the LEDs or trying to bolt things on to the API but ether way. I’ve got some python learning to do. I may just forgo using the keybow.on functionality at all on just record keystrokes from the pins until all are true then output a value.

This started with me just looking at the in the example directory with no real plan on the process or logic I would use so some of the names are kinda random.

#!/usr/bin/env python
import keybow
import time
import operator

multikey = {}
multikeyoutput = {}

def keycounter():
    global multikeyoutput
    buttons_list = []
    compoundkey = None
    for key in multikeyoutput.keys():
        buttons_list.append (int(multikeyoutput.get(key)))
#        print(buttons_list)
    compoundkey = "".join(str(int((button))) for button in buttons_list)
    print("KeyCode: {}".format (int((compoundkey),2)))
    multikeyoutput = {}
    multikey = {}
    button = None

def handle_key(index, state):
    global multikey
    global multikeyoutput
    for i in keybow.pins:
#      print("i is: {}".format (i))
      keystatus = 0
      keystatus = int(operator.not_(keybow.GPIO.input(i)))
      multikey[keybow.pins.index(i)] =  int(bool(multikey.get(keybow.pins.index(i), 0) + keystatus) == True)

    if state:
        keybow.set_led(index, 255, 0, 0)
        print("MultiKey while keys are down: {}".format (multikey))
        multikeyoutput = multikey.copy()
        multikey = {}
        keystatus = None

        keybow.set_led(index, 0, 0, 0)
while True:
    if bool(multikeyoutput):
#    else:

    time.sleep(1.0 / 60.0)