MouseKeys Plugin - separate keys for press and release?

algernon, I tried this and I had to add in a call to releaseMouseButtons to get the mouse buttons to release. Otherwise, even after fixing the typo where you used P instead of R in mouseReleaseMacro, the buttons wouldn’t release.

So it looks like the mouse buttons don’t get cleared each cycle the way the keys do.

Here’s the working code:

static struct {
 bool left, middle, right;
} mouse_buttons;

const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
  switch (macroIndex) {

  case MBL_P:
  case MBM_P:
  case MBR_P:
    mousePressMacro(macroIndex, keyState);
  break;

  case MBL_R:
  case MBM_R:
  case MBR_R:
    mouseReleaseMacro(macroIndex, keyState);
  break;


static void mousePressMacro(uint8_t macro_index, uint8_t key_state) {
  if (keyToggledOn(key_state)) {
    switch (macro_index) {
      case MBL_P:
        mouse_buttons.left = true;
        break;
      case MBM_P:
        mouse_buttons.middle = true;
        break;
      case MBR_P:
        mouse_buttons.right = true;
        break;
    }
  }

  switch (macro_index) {
    case MBL_P:
      if (mouse_buttons.left)
        kaleidoscope::hid::pressMouseButtons(KEY_MOUSE_BTN_L);
      break;
    case MBM_P:
      if (mouse_buttons.middle)
        kaleidoscope::hid::pressMouseButtons(KEY_MOUSE_BTN_M);
      break;
    case MBR_P:
      if (mouse_buttons.right)
        kaleidoscope::hid::pressMouseButtons(KEY_MOUSE_BTN_R);
      break;
  }
}

static void mouseReleaseMacro(uint8_t mouse_index, uint8_t key_state) {
  
 switch (mouse_index) {
    case MBL_R:
      if (mouse_buttons.left)
        kaleidoscope::hid::releaseMouseButtons(KEY_MOUSE_BTN_L);
      break;
    case MBM_R:
      if (mouse_buttons.middle)
        kaleidoscope::hid::releaseMouseButtons(KEY_MOUSE_BTN_M);
      break;
    case MBR_R:
      if (mouse_buttons.right)
        kaleidoscope::hid::releaseMouseButtons(KEY_MOUSE_BTN_R);
      break;
  }
 if (keyToggledOn(key_state)) {
        switch (mouse_index) {
          case MBL_R:
            mouse_buttons.left = false;
            break;
          case MBM_R:
            mouse_buttons.middle = false;
            break;
          case MBR_R:
            mouse_buttons.right = false;
            break;
        }
      }
    }