Ctrl + scroll for zoom not working from keyboard but working from mouse


(Shriramana Sharma) #1

Hello. Since using my mouse’s scroll wheel up/down with Ctrl pressed zooms in and out in my KDE environment, I tried configuring two keys on my Fn layer to LCTRL(Key_mouseScrollUp) and LCTRL(Key_mouseScrollDn). However, they are not producing the desired zooming effect although using the actual mouse’s scroll wheel with Ctrl pressed on the keyboard does.

Please advise. Thank you!


(Gergely Nagy) #2

The LCTRL() macro only works for traditional keyboard keys. The reason for this is purely technical: we have keycodes on the keymap, which the firmware interprets. There’s only so much bits (16) per key, to describe what it does, and if we wanted to support LCTRL with mouse keys, we wouldn’t fit into 16 bits.

To achieve what you want, you can use a macro, like the following:

const macro_t *ctrlScroll(uint8_t keyState, uint8_t macroIndex) {
  Key direction = Key_mouseScrollDn;
  if (macroIndex == M_CTRL_SCROLLUP)
    direction = Key_mouseScrollUp;

  handleKeyswitchEvent(Key_LeftControl, Macros.row, Macros.col, keyState);
  handleKeyswitchEvent(direction, Macros.row, Macros.col, keyState);

  return MACRO_NONE;
}

…or something along these lines. I haven’t tested the above code, so it may be a little buggy. If it is, let me know, and I’ll help fixing it up.


(Shriramana Sharma) #3

Thanks for your reply and help as always! I sorta adapted your code into the following inlined into the macroAction function (somehow I don’t like to clutter the individual macros into separate functions):

    case MACRO_ZOOM_IN:
        if (keyToggledOn(keyState))
        {
            handleKeyswitchEvent(Key_LeftControl, Macros.row, Macros.col, keyState);
            handleKeyswitchEvent(Key_mouseScrollUp, Macros.row, Macros.col, keyState);
        }
        break;

    case MACRO_ZOOM_OUT:
        if (keyToggledOn(keyState))
        {
            handleKeyswitchEvent(Key_LeftControl, Macros.row, Macros.col, keyState);
            handleKeyswitchEvent(Key_mouseScrollDn, Macros.row, Macros.col, keyState);
        }
        break;

(Shriramana Sharma) #4

As a warning to other wannabe programmers here, I initially forgot the two break statements above and due to that triggering either (or one, I’m not really sure) of these macros would send my system into a non-GUI terminal from which only Ctrl+Alt+Del was possible. :slightly_frowning_face:


(Noseglasses) #5

We are all wannabe programmers. We will never be true programmers as we are learning every day something new (at least I do). Actually, there are no complete C++ programmers. Before you can reach this point there will always come a new version of the ISO standard that you have to adopt :wink:


(Shriramana Sharma) #6

Hello @algernon. How different is the above from using MACROSDOWN? And it seems to be sequential so how does it make it that Control modifies the following mouse scroll key?

Thanks!


(Gergely Nagy) #7

You can’t use a variable like direction with Macro.play(), nor return a macro with a variable, because the argument of Macro.play, and the return value of macroActions must be computed at compile-time. The above code does essentially the same, but allowing run-time conditions.

There’s no report sent between the two, no clearing reports, etc. It’s like you pressed both at the exact same time, as far as the host is concerned.