Macro That Runs Until Key Is Pressed


In Media Composer I have a superbin window with different tabs. I would like to have a macro that toggles through those tabs with one second duration until a certain key is pressed and stop (means: activate) at that position

Is this possible in Keyboard Maestro?

Cheers Simon

Hey Simon,

Not many on the forum use Media Composer, so it'd be a good idea to post a screenshot and describe how this might be done by hand.


One thought though – take a look a the While action with a key condition.

Hi @ccstone,

Thanks for getting back to me.

Basically all I want is to press the 'space bar' to stop at the current position. I used the 'While' action and set a keyboard condition but it does not work.


You set the condition to be "while the space key is down", probably the reverse of what you actually want. Try reversing the logic so it is "while space key is not down":

Thanks Nige.

I modified it but it still does not work like it should. When I press the space bar for about a second it stops. but not at the current position.

I'm looking for something like 'perform a series of actions until a certain key is pressed and stop at that point.'

Superbin toggle.kmmacros (10.9 KB)

Macro Image


The condition is evaluated each time the loop returns to its beginning. So if you press the space bar halfway through the loop it will do all the remaining "Move and Click Mouse" actions then stop.

So you'll need an action that clicks at the first (absolute) position and then start your loop, and that loop should contain a single "Move and Click at (180,0)..." and a pause.

You'll still be in for problems -- what happens when you run out of tabs to click? -- so do look for another method. Is there no keyboard shortcut to cycle through the tabs?

Unfortunately there isn't a shortcut for that.
You are right ('what happens when you run out of tabs to click?') This is another problem but since my superbin-interface does not change with the amount of my 7 tabs I could define it to have a loop that goes 7 times right and then 7 times left (a little clumsy and not really a cycle but I could live with that.) I would be already happy to achieve a 'interrupting a loop with a keyboard trigger'-action.

Here are some actions that might do what you want. These aren't stand-alone macros -- copy the action and use them instead of your current "loop through tabs" section.

This should work through tabs the "normal" way -- from tab 7 it will jump back to tab 1:

Effect Loop - Normal.kmmacros (7.1 KB)


Totally untested so you'll probably have to play around a bit. But the theory is:

  1. Click the first tab
  2. Set a counter variable for the tab clicked
  3. While the space key is not held down...
    1. If the counter is 7
      1. then you are on the last tab -- reset counter to 0 and click the first tab
      2. else click the next tab to the right
    2. Increment the counter

This alternative method should work left-to-right until the last tab, then work backwards again right-to-left:

Effect Loop.kmmacros (9.7 KB)


Again untested, but the theory is:

  1. Click the first tab
  2. Set a counter variable for the tab clicked and a text variable for the direction of movement
  3. While the space key is not held down...
    a. Move in the current direction of movement to click the next tab
    b. Increment the counter
    c. If the counter is 7 then you are on the last tab for that direction of movement -- reset counter to 1 and change the direction variable

There's probably cleaner ways to do both of these, especially to exit the loop -- my worry is that you'll have to hold down the space bar for up to 0.5s for it to register, because of the pause.

(You might be able to get around that by changing the "loop" pause to "Pause until space key is pressed" but with a timeout of 0.5s -- it'll only pause for 0.5s if you do nothing but instantly break the pause, return to the loop test, and exit the loop if you press the space bar.)

1 Like

Hey Guys,

I think what I'd do in this situation is use a palette with single-key triggers like 'H' and 'L' (Vi style keyboard navigation).

Forward one and back one is covered – and last-position is saved.

Last position is reset whenever the palette is activated.

Add another button and trigger for reset last-position.

Or maybe Home, End, PgUp for previous, PgDn for next.

I generally use F1 to pop up this type of single-key-trigger palette when I want extraordinary navigation features.

That trigger is easy for me to reach and has become very intuitive after developing muscle memory over years of use.

Here's the one I have in Google Chrome:


The visible palette reminds me I'm in navigation mode.


1 Like

NIce one, Nige...that works!
The only thing is I have to press the button a little longer.
When I change it 0.2 seconds it works better but I have to be quick!
Anyhow that helps a lot. Thanks so much!

Cool. I check that out! Thanks Chris...

One more thought.
You guys have any idea to have that loop not time-based (0.2 seconds) but by pressing one key multiple times until I reach the tab I want. That would be even more handy.

Try the workaround I suggested above -- replace the "Pause for 0.5 seconds action" with


...and click on that action's cogwheel and set the "Set Action Timeout" options to

Hopefully the action will either timeout after 0.5s and the loop will continue, activating the next tab, or you pressing the space bar will cancel the pause and, because the space bar is still down, the loop will cancel and you'll be left with the tab you want selected.

Yes, that's what I was suggesting in Post #8.

But you can do it with one or more hotkey triggered macros just as well.

  • Save the initial position to a global variable and increment it each time you press the trigger.
  • Figure out how you're going to reset the last position.