Two questions re macros


(Shriramana Sharma) #1

These questions were in my mind already and I will take as example this quote from How does one make a key that turns the LEDs off?:

  1. It isn’t really necessary to create a separate function for each macro is it? We can just inline the action inside the case block, no?
  2. Why do we have to test if (keyToggledOn(key_state)) at all? Isn’t this function fired only when the key is pressed?

(tiltowaitt) #2

While I don’t know about #2 (been wondering it myself), you’re correct that you can inline macros into the case block. It might be a “best practices” or coding style kind of thing.


(Michael Richters) #3

I believe it is now, but that’s a fairly recent change. (By which I mean that anyone using firmware that’s not up-to-date would need the conditional to keep the macro from executing regardless of the keyswitch state).


(Gergely Nagy) #4

No, it also fires when the key is released. It also fires every cycle while the key is held. It also used to fire when the key was idle, which had its uses, but we removed that feature, because it made the main loop a lot faster. Always fast > marginally useful use-case.

So with an up-to-date Kaleidoscope, macros fire when the key toggles on, while it is pressed, and when it is toggled off. This is by design, and is useful, I don’t see it changing anytime soon. If you’re curious about why it is useful, let me know, and I’ll present some examples :slight_smile: