How to prevent accidental keystrokes while macro is running

I have a very long macro which is helping me automate several things for a very tedious and large project. My macro has several "Prompt for user input" actions. However, once in a while (when I'm tired or at 2 am) I get ahead of myself and hit the ENTER key right before the prompts pop-up.

Is there really no way to prevent this?

I can think of two approaches (which can be used in combination):

  1. Use a Pause Until action to prevent the prompt from appearing until the workflow is ready for it.

  2. Use a second prompt (a JavaScript alert wouldn't hurt if the first prompt is a Custom HTML Prompt) to confirm the first prompt. You'd wrap that in a loop in case the second prompt was not confirmed.

Thanks for your reply. I don't think using a "Pause Until" really addresses this issue because that would only prevent Keyboard Maestro from showing the prompt until a condition is true (or not). What I'd like to do is prevent anything from happening in case I hit ANY key on the keyboard before a prompt shows up.

Of course, paying close attention is the way to go but as I mentioned in my original post, after a long while of repetitive stuff humans get tired and make mistakes.

I'm not sure I understand the second suggestion about using a JavaScript alert but I have a feeling that might not prevent accidental keystrokes while the macro is running either.

I guess I should have written my request differently: Is there a way to disable the keyboard throughout the entire macro except when a "Prompt for user input" pops up?

Thanks!

See these solutions.

1 Like

Thanks again. Unfortunately, except for KeyboardCleanTool the other two solutions are no longer available and KeyboardCleanTool doesn't have shortcuts to turn it on or off so that won't work either.

Hopefully someone else has other tricks?

I think you missed the 3rd tool in @mrpasini‘s post: KeyboardLocker which is definitely still available. I know nothing more about it - just thought I’d point it out.

You could make the prompt ask for a password, and put that in a loop to stop it being bypassed e.g. Escape key or Enter key

KeyboardLocker doesn't address what I am trying to achieve.

KeyboardLocker only disables the keyboard when it's the frontmost application. This won't work.

Thinking about this in more detail, I think the only thing I really need is a way to only disable the keyboard keys that respond to buttons on the prompts but they would only be disabled during the "non-prompt" periods of the macro. I've created a simple graphic to illustrate this:

Untitled

So imagine that you have to run this macro hundreds of times. It gets to a point where you try to do it quickly and wind up hitting the ENTER key a split second before the Prompt. This can/will screw up whatever task you are using the macro for. In my case, for example, hitting ENTER right before the prompt causes Adobe After Effects to open the selected layer thus screwing the process.

I run across this issue pretty much on every macro that I use. Am I the only one wishing there was a way to prevent accidentally hitting unwanted keystrokes during a macro?

Hope to hear your opinions.

Thank you.

Can't you just put two or three Alerts before the prompts in question? That would slow you down and prevent mishap or behavioral issue.

Thanks for the suggestion. Putting an Alert is probably helpful but not a solution as that still wouldn't prevent me from hitting the ENTER key too early.

Well, there's always the Pavlovian approach. Put a Play Sound macro in front of your Continue prompt and train yourself not to touch the keyboard until you hear the sound.

Yep. This a a behavioral issue because @project_guru is a human computer and he moves too fast. We need to have Peter create an action to handcuff him for a three count before his prompts show up. :smiley:

My impression is that your macro, when it is finished with Actions 1-10, puts up a dialogue box with the OK/Cancel and this is responsive to the user hitting the Enter key. I assume the problem is that the Enter key causes some effect in whatever is the foremost application running Action 10 so if it is hit prematurely, it causes some undesirable effect.
How about rewriting the macro so that the OK/Cancel dialog is responsive to clicking on some pair of Function keys. Choose Function keys that have no effect on the foremost application. (you could even turn off the Function keys until they are ready to be hit) Then your 2:00 AM fingers are quivering over these particular Function keys rather than the Enter key. If they prematurely hit the Function keys nothing happens.
In a similar situation, I also have used the Pavlovian sound cue to help me not "jump the gun" as suggested above

Your idea of using keys that have no effect on the Application is a good idea. I will try that next time.

How would you turn these off?

Thanks.

I happen to use a little app called Palua. It sits in your menu bar and allows you to toggle back and forth easily between Function Mode and Apple Mode. When you are in Apple Mode the function keys have a default behavior and do things like pushing the volume up and down or brighten/dim the screen. So in Apple Mode, those function keys will not interfere with your macro.

If you hold down the fn key before you hit the function key then they become "classic" function keys and can do whatever you want. In my world, they are common triggers for Keyboard Maestro scripts.

It can be annoying to always have to hold down the fn key. To avoid this, you can put the function keys into Function Mode. In this mode, they no longer invoke the Apple Mode functions. They just await your personal use. Basically, the function keys start acting as if you were holding down the fn key.

Palua comes with a toggle key combination that toggles between Function Mode and Apple Mode. So it is easy in a Keyboard Maestro script to put it into Apple Mode when you want it to be "unresponsive" and then immediately before it is time for you to provide your input, put it into Function Mode.

As I prepared this Reply, I find that Palua is no longer available (It was a $1.00 app). I have had it forever and it still works with Mojave which is what I use. I love the app and there are some murmurings that its disappearance is "temporary" but I would not put too much stock in that. It apparently has been out of the App store for years. I found a discussion in the forum ( Toggling F-Keys) that discusses approaches to this problem without using Palua. Someone provided an AppleScript to do this. I am surprised that this is as complicated as it is, but I presume you could copy that AppleScript.

You can go to System Preferences/Keyboard and click/unclick a checkbox to Use F1, F2, etc. keys as standard function keys. If you did not want to use AppleScript, you might be able to use Keyboard Maestro to navigate to this location and click/unclick this checkbox but that might be a little elaborate in itself.

I do not have a laptop with a Touch Bar but apparently you can arrange it that when a certain app is running the function keys show up in the Touch Bar. https://support.apple.com/en-us/HT207240. I cannot test this but if the app running your actions 1-10 does nothing untoward when you type on a function key, you could make these function keys available and they would do nothing unless you had moved into a place in your macro that they had an effect.

This is great information. I will try one or some of the suggestions on that other thread.

I appreciate the time you've taken to reply.

Regards, Xavier