What are `INJECTED` keys for?

This may be a bit of a stupid question, but I don’t understand the purpose of the INJECTED bit in the keyswitch state. Why is it there? It seems redundant with UNKNOWN_KEYSWITCH_LOCATION – is there some utility to it that escapes me?

INJECTED is to allow plugins to ignore key events, so they won’t end up in an endless loop (like SpaceCadet trying to turn a shift into a paren over and over and over again). It is not redundant with UNKNOWN_KEYSWITCH_LOCATION, because plenty of INJECTED keys retain the coordinates of the originating key (like SpaceCadet). Whenever the cost of storing the original location is cheap (or zero) we tried to preserve the coordinates. We only use UNKNOWN_KEYSWITCH_LOCATION when the original position is not available, usually because it would be too complex, or too big to store. For example, for one-shot keys, we’d have to store the position of all active oneshots, and that’d be costy. With SpaceCadet, we do everything in a single event handler, which gets the coordinates as arguments anyway, so the cost is zero.

So it’s a way of preventing infinite loops (event handlers calling more event handlers)?

Yeah, that they are.

Thanks, @algernon. You’re the best!