How do I do a Pause Until with Logical OR of Two Keystrokes with Different Modifier Keys?

How do I setup a logical OR for a Pause Until action for keystrokes of


~~~ OR ~~~
ESC

something like this:

image

The green "OK" is of course just a comment action.

Any ideas?

You can obviously Pause Until with a logical or by using the “any of the following are true”, but you want both an OR and an AND:

(Return Key Pressed AND Option Key Down) OR Escape is Down

To resolve this, just consider that Pause Until is really the same as:

  • Loop Forever
    • Break From Loop If Condition

Loop Forever can be done via While Calculation “1”

And to do an OR:

  • Loop Forever
    • Break From Loop If Condition1
    • Break From Loop If Condition2

Break From Loop If is just If Then Else and Break From Loop.

Of course, you can extract the initial Condition1 into the Loop condition:

  • While Condition1
    • Break From Loop If Condition2

But I would probably prefer the symmetry of the two If Then Else actions, but it is a matter of taste.

You can also add a short pause to the While loop to reduce the CPU load at the expense of a small addition in lag (say 0.1 seconds for example). This is often a good idea for Pause Until actions, especially if the condition is expensive (which it is not in this case).

1 Like

Exactly.

That should work! :+1:
Many thanks.

1 Like

Chiming in here since this thread seems to be the closest thing to a solution for my problem I can find, however I still can't quite get it :man_facepalming:t2:. The pseudo logic is helpful, I think I'm just having a mental block...

Similarly, I'm looking to continue or break a loop based on one of two key commands:

WHILE all of the following are true (Counter var <= StopLoopValue var)
{
Do ABC

// at this point I am doing tasks manually for an indefinite period of time. This includes keystrokes, mouse clicks, etc.

 Pause Until CMD+Return is pressed 
    Counter+1, return to beginning of loop
 OR
 Pause Until CTRL+OPT+CMD+DELETE is pressed
    Break Loop

}

I'm struggling with is how to structure the conditional of the If Then Else in this situation. If we say "any of the following are true" with the following it will naturally undesirable results as any of the following will trigger true:

Modifier: CMD
Key: Return
Modifier: CTRL, OPT, CMD
Key: Delete

Is it possible to group these within the conditional as so?

Modifier: CMD + Key: Return

Modifier: CTRL, OPT, CMD + Key: Delete

Or, is there of a nested If Then Else approach I'm not considering?

@ JMichaelTX & peternlewis - I probably should have tagged you in my original posting, as I'm unsure how the visibility of a one year old thread's resurrection is handled. Any thoughts you have on this would be very appreciated :slightly_smiling_face:

For detecting keystrokes, it is better to use separately triggered macros. If you want to capture the Command-Return, use a Hot Key trigger. If you want to just detect the keystroke but let it behave normally, use a USB Device Key trigger.

In any event, what you would do is:

  • Enable Macro “Detect Command-Return”
  • Enable Macro “Detect COC-Delete”
  • While Counter var <= StopLoopValue var
    • Do ABC
    • Set variable “Command Return Detected” to 0
    • Set variable “COC Delete Detected” to 0
    • Pause Until calculation “Command Return Detected OR COC Delete Detected”
    • If variable Command Return Detected is 1
    • Break From Loop
  • Disable Macro “Detect Command-Return”
  • Disable Macro “Detect COC-Delete”

The two other macros are simply:

Macro “Detect Command-Return”
Hot Key (or USB Device Key) trigger on Command-Return
Set variable “Command Return Detected” to 1

The reason it is better to use a macro trigger to detect a keystroke is because it is easy to miss detection of a keystroke since they can happen fast - trying to detect that the key is down may miss it if Keyboard Maestro is not fast enough, where as the triggers detect the key going down so cannot miss them happening.

2 Likes

Thanks so much! That was the breakthrough I needed. I can't emphasize enough how helpful it is to have you so active in the KM community forums!

2 Likes