Skip to content

[Enhancement] Conditional module/extension #956

@p3lim

Description

@p3lim

Is your feature request related to a problem? Please describe.

I use a lot of keys that depend on other keys being pressed, and the closest solution to this in KMK that I've found is to create a a bunch of custom key like this:

from kmk.keys import make_key

def on_pressed(key, keyboard, KC, *args, **kwargs):
  SPACE = {KC.SPACE}
  if SPACE.intersection(keyboard.keys_pressed):
    keyboard.keys_pressed.add(KC.A)
  else:
    keyboard.keys_pressed.add(KC.B)
  keyboard.hid_pending = True
  return keyboard

def on_released(key, keyboard, KC, *args, **kwargs):
  keyboard.keys_pressed.discard(KC.A)
  keyboard.keys_pressed.discard(KC.B)
  keyboard.hid_pending = True
  return keyboard

make_key(names=('SPAB'), on_press=on_pressed, on_release=on_released)

Describe the solution you'd like

A module/extension that makes this easier. Using the same example keys as above:

# syntax:
#  if   key(s)     then  else
KC.CK((KC.SPACE,), KC.A, KC.B)

This might be very specific to my usecase, so it's understandable if it gets denied, I just want to clean up my messy main.py 😄.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions