Using an If Then Else Based on a Keypress

Hello, in the action below, I want to cancel the macro if I press escape, otherwise continue, but logically I have to query the user beforehand.
I could not find any query action.
How would create an action which would:

  • cancel macro if press escape
  • continue if press $
    thank you


Not sure if I understand the question properly. Let’s see:

A query in its most simple form would be an explicit user prompt:

In the default config (as shown above) it cancels the macro if you press Escape. (It continues if you press Return.)

If your macro has any kind of repeat loop, you could simply build a condition into the loop, like the one you have shown in your post, or an Assertion action with the appropriate key condition. When Escape is down, the macro will be canceled, otherwise the loop continues.

Is it necessary to have a specific continue key, if you already have a specific cancel key? (This is also contradicting what you said at the beginning of your post: “otherwise continue”.)

1 Like

Wouldn't this work? One little catch: it will continue either if the users presses "$" or "4". Otherwise I think this is what you asked for.

thank you for taking the time to reply.
I don't understand: in your macro, where is the prompt, ie ask user to press escape to cancel or 4 to continue.

I am going to test it and get back to you. Thank you very much

You didn't ask for a "prompt" in your original question. All you said is "continue if press $" and my code does that. I had no idea you wanted a prompt. All you said was if the user presses "$" to continue.

1 Like

thank you very much. I will review the user manual on the prompt action and use your suggestion

You are right and I am sorry for not being clear.
Thank you for the macro.
Once I started writing the action, I realized that at some point, the user has to be prompted for a keypress.
thanks again

Most people who ask questions are asking very specific questions, resulting in perhaps not the best answer possible. I'm going to take a guess that what you really want is a way for a macro to know if a user is "ready" for the next step. Here are a couple of different ways I go about that.

The first action waits until the user has done nothing for 60 seconds. I find this a good way for my macro to know if the user is "ready" (ie, not busy). Therefore no keystroke is required, instead the absence of keystroke and mouse movements trigger the macro to continue:

Another way with a slightly different effect is to insert the following statement from time to time inside my macros: (essentially the CAPS LOCK key becomes the equivalent of a PAUSE key).

Sometimes I find it helpful to tell the user that the program is pausing, like this:

I have a few other more complex macros that do something similar. For example I once made a macro that said "if the user's iPhone is within Wifi range of this computer then...". I also had one that allowed the user to speak to the computer to activate a macro or change a condition for macros to evaluate. I don't think you need those macros, but consider the ideas to be food for thought.

1 Like

extremely interesting and useful !!
thank you so much !

There is a slight bug in the CAPS LOCK pause statements above. They don't actually pause while the CAPS LOCK button is in the CAPS LOCK STATE, they only pause when the button is physically pressed.

I never noticed that because in my case I was only using it in such a way that I had to turn it ON briefly to continue my program. So for me it worked fine this way.

But I think it should work differently. It should work by determining the CAPS LOCK STATE not the physical position of the CAPS LOCK KEY. This may be exactly how KM intended to behave, but I feel that it would be far more sensible to behave based on the STATE.

1 Like

So I put my mind to it (mostly by googling) and I think I solved how to detect if the state of macOS in in CAPS LOCK, as opposed to whether the key is down. I create a variable called CapsLockState and add this one macro to my system:

Then you access the state by evaluating the variable CapsLockState, for example this should now work as expected:


thank you very much for all your help. You did a lot of work !

You are welcome. I need these solutions too, so I benefit as much as you.

The Caps Lock key is particularly good as a pause button because it's the only key with a light indicator.

Hmm, maybe I can provide more feedback via the Touch Bar, if I had one of those.

1 Like