How to run an action or a different macro based on which key is pressed

I need KM to start a macro, then pause for a key to be pressed—either the return key or the tab key—then run a different action (or external macro) base on which key was pushed. I tried the pause function, but couldn’t figure out how to make the macro continue with different actions based on the key pressed; and I tried the if/else function but couldn’t figure out how to pause for a key to be pressed. Anyone know how to do this? Thanks!

I think the Action “Prompt for User Input” in the Variables group should work for you.

Here’s an example from one of my marcros:


Prompt for User Input ‘Select Color’
Select COLOR to be applied to text
Input the following variables:
ColorSelected (default to ‘Black|Blue|Red|Green’)
Finish with the following buttons:
OK
Cancel (cancel macro)
Store button pressed in variable ‘Result Button’.

You can then use the Action “If Then Else” based on the Variable set above.

I use a technique in the wrapper macros of Markdown for Keyboard MaestroMake%20Italic.kmmacros “km-markdown-library/02)Make Italic.kmmacros at master · Zettt/km-markdown-library · GitHub”) that you may be able to use, and maybe you want to check out the Execute Actions Until Conditions Met action. This action can stop its actions when a modifier key is pressed. I use this for a macro that clicks a specific spot in Safari tabs, all from one specific site, and then move on to the next tab, to do the same.

Execute Actions Until Conditions Met
Move and Click at (0,0) from the Current Mouse Location
Type the ⇧⌘] Keystroke
Pause for 0.5 Seconds

Cheers!

Thanks, JMichaelTX & Zetti! Swamped with work right now, so it’ll take me a couple days to try out your suggestions. I’ll report back when I do. Thanks, again.

An easy way is just give both macros the same hot key and Keyboard Maestro will ask you which one you want and set up two temporary hot keys for you based on the names of the macros.

Alternatively, another easy way is to create a macro group, configured to optionally display a palette for one action after a hot key that activates it, and then put your two macros in there, each with the second hot key key as the trigger (and since they are only active immediately after the first hot key, they can be anything simple, even just letters.


I was away from email over the Easter break - sorry for any delays.

Keyboard Maestro http://www.keyboardmaestro.com/ Editors’ Choice Award winner.
Macros for your Mac http://www.stairways.com/ http://download.keyboardmaestro.com/
Join us on the Keyboard Maestro forum http://forum.keyboardmaestro.com/