Sorely Needed: Elaborate Detailed Tutorial on User Input Actions With Many Examples Including Simple Keypress

I have been using KM for more than 5 years, created probably 1,000 macros, some of which are quite elaborate thanks to the help of @jm and others.

I am writing this post because despite all my efforts, including reading the documentation (which does not mention how to manage keypress as an input) and trial and error creating macros, I am simply unable to understand how to use the prompt for user input actions (such as Prompt For User Input, Prompt With List etc).

After frustrating attempts, I have always end up using conflict palettes.

I am comfortable with pause until, if then else and case actions but they are of no help in this situation.

A basic example: I am unable to create simple keypress embranchements in macros, for example something along the lines of
pause for user input → press a to ..., press b to ... press c to .... A, B and C representing different series of actions. In its simplest form, it could be

  • press a to display “hello A”
  • press b to display “hello B”
  • press c to display “hello C”

Although I am not very smart according to my spouse, I suspect that quite a few forum members avoid the user input route for this reasons above.

A detailed tutorial on user input actions with many examples would be greatly appreciated.

thank you

Hi @ronald

To do your particular example, you can set up a Prompt for User Input Action with your own buttons and then use the result in a Switch Case Action to display the text you want depending on which button was pressed.

image

The Prompt for User Input is extremely versatile - it can set Variables and Token Values. In the case of the "button" example you asked for, it is setting the Token %PromptButton% to whatever you have called the button.

Then the Switch Case Action does something different depending on what the value of %PromptButton% is.
EXAMPLE Prompt Buttons A,B,C.kmmacros (32.6 KB)
image

In my case, I've kept discovering new uses for Prompt for User Input. I found it was really worth going through the Wiki Page step by step. It is actually full of lots of useful information on how the various parts of the Action work.

https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input

When setting up my own Prompt for User Input Actions I have found it is helpful to use the gear menu in the Action to keep "trying" the Action. This displays what the Prompt will look like and allows you to edit button names, positions etc before running the whole Macro.

image

[ EDIT ] - Reading your post again, I think you are wanting to press a key on the keyboard rather than click on a button. But this just shows how versatile Keyboard Maestro is. The button names can be altered to be given a default key press by adding that single letter after "/" in the button name. So, button A has been renamed A/A (the part before the "/" is the Button name and value, the letter after the "/" is allowing that single letter to be pressed on the keyboard to do the same thing as clicking the button). All of this is on the Wiki Page.

With this modified Macro, when the User Prompt comes up pressing a,b or c on the keyboard also works to make the choice:

EXAMPLE Prompt Buttons + Key Press A,B,C.kmmacros (32.6 KB)
image

I have kept the Buttons displaying as A,B,C but if I had wanted something else to be written on them that can work too.

A/A
B/B
C/C

could have been in the prompt:

First Choice/A
Second Choice/B
Third Choice/C

image

In which case, pressing the physical keys a,b or c would still make the choice. The only difference is that the following Switch Case Action would need to be changed to the following (i.e. A,B,C changed to First Choice, Second Choice, Third Choice):

image

Here is another approach using a Variable instead of Buttons in the Prompt for User Input Action. In this case the choice can be made either by choosing from the Dropdown List or typing the single letter on the keyboard:

image

EXAMPLE Prompt Using Variable.kmmacros (32.5 KB)
image

All this and more can be found on the Wiki Page - like I said, I found it really useful to try out all the various variations the Wiki page shows. This illustration is particularly good. It shows everything I have been mentioning above (and lots more).
https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input

image

Each example in the image above is full of subtle detail and it's really worth spending some time just trying out each one until you get what it does.

Use a Display Text in a Window Action to display the "choice". i.e. if you are trying out the third one down, "Popup Menu Default" have a Display Text in a Window Action following the Prompt, set to show the Text %Variable%Popup Menu Default%

image

You make your "choice" via the Prompt for User Input Action - then that "choice" gets made use of in your following Actions. I used a Switch Case Action but could have also made use of the "choice" in an If/Then/Else Action (and probably an almost infinite number of other ways too).

Once you get the basic concept, the rest is just bolting Actions together until you get something that works :grinning:

12 Likes

A superb post !! Fantastic introduction to the topic of User Prompt. I very much appreciate your didactic approach.

Thanks to you, I can now say that I am on the right track and think I understand the prompt for button, keypress and drop down list.

And using the gear or context menu to try actions definitely make life easier.

I am still confused by the following, but am going to sit down and read the wiki line by line

Thanks again VERY much for your help !

3 Likes

Hey @ronald, There's this macro that I use as a starting point when I need to do a list or prompt:

@Zabobon 's might be easier to use since he split them and explained it thoroughly.
great explanation!

5 Likes

a very useful tip. thanks very much. I found it a bit difficult to understand. Now much better with @Zabobon 's explanation.

I am going through the examples with variables one by one as you suggested and read through @JMichaelTX 's Post. I would have 2 questions

  1. Popup and keypress
    In the snapshot below, I create a popup menu with 3 choices.
    I notice that it does not respond to keypress (ie just press C instead of click on dropdown list → choose C). I tried adding /A, /B and /C but it did not work. Is there anything I can do to make the drop down list responsive to simple keypresses (first letter for each choice) ?

  2. In my display action, I use %Variable%PopupMenuChoice% and it works fine. I was wondering why you were using %Variable%Popup Menu Default%

Thanks again very much !

I think you have put some extra spaces in the list. It should be A|B|C not A|B | C | as you have it.

Only because "Popup Menu Default" is the example text on the Wiki page. The variable can be called anything you like.

image

The example image on the Wiki is packed full of information and examples - but it's always easier to understand by actual example Macros. For my own benefit going forward, I've made that Wiki example into a Cheat Sheet Macro that can be run to test what each of the options does.

image

I've included a couple of things that weren't in the original Wiki Image - the A,B,C buttons that were mentioned in this thread and a Local Variable Prompt (Local Variables are really good for Choices in Macros because they reset themselves to blank once the Macro has run).

As well as putting a "/some letter" at the end of button name to allow the button to be chosen by a key press, putting "/." at the end of the Cancel Button name allows Esc to be pressed to Cancel the Prompt.

Notice how the OK button is blue, which means hitting the Return Key will select it. If you want to make another Button the default, you put a "/" at the end of its name. So, a button named Choice A/ would be highlighted blue and be the default Button.

Also (as that same Wiki page says) it's good interface design to make sure the Cancel Button is the left-most button and Enter is the right-most. Funnily enough the example on the Wiki page breaks its own advice by putting the Cancel Button in the middle :rofl:

Anyway, there's plenty more stuff on that Wiki Page that can be incorporated but I think this demos the main things.

EXAMPLE Prompt Cheat Sheet.kmmacros (32.2 KB)
image

2 Likes

thanks very much.

Your cheat sheet is a very useful template that I can modify and use for each type of input.

Sorry but I still don't understand why the following does not respond to keypresses (I deleted the spaces)

when I press “c”, I would expect the list to display the C line, after which I would press enter (for OK)

image

You still have a few typos

It should be A|B|C for a Popup list

You only use the "/" for the buttons.

(Popup Lists already know to allow typing to select them, without having to tell them)

There is an example in the Cheat Sheet Macro I uploaded:

Oh - but one caveat - If you want to have the Popup appear and just be able to type a letter, that prompt Popup should be the only prompt (so that it is highlighted and ready for selection).
image

image

For your original question, of choosing one of A,B,C I would say the button choice (with keys set using "/") is better.
image

image

1 Like

Great explanation. thanks very much. I think that you are right: a menu of buttons is best if I want a response to keypress. I will save dropdown lists when I use text files containing the list.
thanks again very much

This is a great post both for the humor and practicality.

Although I can't help with spousal difficulties, I can suggest a way to implement the tutorial idea: provide a list of km macros which are voted upon for their (1) usefulness, (2) description, (3) keywords.

In other words, new users need something like stackoverflow which unfortunately returns less than 150 hits when you search for "keyboard maestro".

4 Likes

thank you for your reply.
An advantage of having many examples is that you end up editing examples to create new macros instead of having to re-create everything from scratch, especially in the area of prompt for user action which is fraught with potential errors for the less KM savvy.

Have you looked at this @Tony ?

Although I’m not a newbie I do consider every new opportunity to use KM as an opportunity to learn from others which is why my favourite resources are this forum and the KM wiki both of which are easily searchable. What isn’t easy, though, is finding the right search term and I regularly resort to searching several times before I find what I’m looking for. For those times when my searches turn up empty I ask for help in the forum.

This is not stackoverflow but it is devoted to KM, scripting and is also a very friendly place.

3 Likes

Thanks. I'm slowly learning KM, and it's good to know this is available.

Even with the few macros I have written I've already discovered the benefits of rewriting them to accomplish the same thing in better ways. I'm guessing there are probably a lot of tricks that one can learn through such experiences to become an expert. But unlike other programming experiences I have had, there are so many different options with KM that it's a little bewildering.

That's why I think stackoverflow could be invaluable if we could just build up a critical mass of people who use it. And of course that would bring other people in. I'm not trying to sell stackoverflow or anything - i've just found it very useful to solve my problems and I believe it's become the accepted way to solve problems in the programming community. I don't use it that much but when I do it's incredibly helpful. And I also like helping people on it.

I suggest encouraging people to post their KM questions/solutions on stack overflow in order to generate such a critical mass. For example, if you have a macro that works somewhat but could be better you post it and ask for advice. You could even answer your own question.

Nothing would have to change on the KM site. And the advantage would be that the burden of maintaining everything would be shifted. And the great search features and large community of course.

I can't say there's anything wrong with that site. I often get directed there from google and get good answers. But for me personally I'm happy with this website which has lots of great features, and I don't like the idea of giving my email address out to another website whose owners I don't know much about, when I don't know what they will do with my email address.

If they had a "Sign in with Apple" button on their login page, I'd give it more consideration. Why don't they support that?

1 Like