Key chords

I'd like to define a Keyboard Maestro macro that I can trigger if I enter a certain key chord.

Key chords are sequences of two hot key presses. Many editors like Emacs, Visual Studio etc. support them and they can vastly expand the set of possible hot key combinations one can use to manage any action.

For example, I could bind Cmd+S Cmd+N to "next song in Spotify" (i.e. S => Spotify => N = Next Song).

Does Keyboard Maestro support chords?

In short: No.

But you might be able to do something similar using a Typed String trigger.

So with this you would NOT use a modifier key, but a sequence of normal keys.
Maybe something like:
where "𝍖" is the SPACE key.

as the trigger for the spotify next song.

One important caution here is that you should use typed string triggers ONLY in a text field, and KM will (by default) delete what you typed before performing the Actions in your Macro.

You could also use a Macro Group Palettes. Trigger the palette with the first keystroke, and then the specific Macro with the second.

I realize that “try another app” might not be a solution that appeals to some folks, but Apptivate can do “chords”, and those chords can trigger scripts, which could include Keyboard Maestro macros.

It’s a free app (hasn’t been updated in awhile, unfortunately, but it worked OK last time I tried it) so you can download it and try it out.


See How do I use a multiple keystroke trigger? for a discussion of options.

Yes and no. Keyboard Maestro supports chords, but the keys will always be swallowed (ie, Command-S in your case will always be swallowed, which would be bad). The FAQ explains why this is necessary for proper behaviour.

So I read the FAQ carefully and if I'm not misunderstanding, there should be the possibility of doing more than what is currently possible given the system of constraints.

Logic dictates that the Option-F A should go through to the system unimpeded, but Option-F R should be swallowed entirely. But this is impossible. The only way to do it would be to swallow the Option-F key, and then swallow the second key and then resubmit the Option F and the second key unless it matches Option-F R.

However, that is fraught with peril and cannot work robustly in the presence of other applications placing things on the keyboard event queue (or even a sufficiently fast typist).

For example, suppose you quickly typed Option-F A B. Keyboard Maestro would have swallowed the Option F and then the A, and then resubmitted it to the event queue, resulting in the stream of characters B, Option-F, A. There is no way to avoid this race condition, and as such Keyboard Maestro does not support any such mechanism.

In particular, what if I reserve Option-F entirely for Keyboard Maestro. In other words, assume that no matter what it is swallowed —just as would be expected if I only mapped Option-F.

However, in this case, I also specify that afterward, if R (or Option-R) is typed, then that is also swallowed. I'm not sure I see any issue with the scenario. Of course I am giving up any possibility that the application can use for example Option-F R to mean something in particular (or anything else that follows Option-F). In fact, both keys would be swallowed if typed. Which is exactly what happens in Emacs.

At most, it just complains "Option-F R is undefined" and moves on. No need to put anything back on the event queue. No race condition.

Is there any flaw in this logic? This seems like it would enable me to use chords like Ctrl-C Ctrl-C, Ctrl-C Ctrl-K, etc. to take actions, just as in Emacs. Of course I am giving up not only Ctrl-C, but the next keystroke afterward.

But that's a price that any user of a chording keyboard app is willing to pay for more flexibility! (and Keyboard Maestro is incredibly flexible)

Yes, and given that restriction, you can do this easily.

Create a Macro Group, configure it to be active for one action when you press the Option-F key, and put your macros in there with whatever hot key you desire for the second key.