Keystroke as variable test

I'm trying to get the user to type in a keystroke, that ideally must be saved as a variable, so I can use that variable later as a keystroke further in the macro (and sub macros) to trigger a shortcut thats program specific.

Keystroke as variable test.kmmacros (2.1 KB)

So in my example that keystroke which defaults as "enter" i want to have as "VarKeyStrokeShortcut"

Hey Gideon,

There's no way to have Keyboard Maestro's Prompt for User Input action take a keyboard shortcut as input.

I suppose you could give the user a range of choices and then create your Type a Keystroke action from the raw XML.

See Copy as XML in the Edit menu of the Keyboard Maestro Editor.

Or you could have a number of pre-built actions in submacros you could call.

But your choices here are pretty limited.


Thanks for your reply Chris.
How would one go about using XML's? I have no experience with that

If you are in a typing context (ie, somewhere you can type), or alternatively in a context where you know something can be typed without causing any problems, then you can use the Typed String trigger with a regular expression to capture a typed character. For example this macro will capture any digit that is typed and then use the digit in the action.

So it depends a little on what you are actually trying to do.

Capture Typed Digit.kmmacros (1.8 KB)

Thanks Peter.
This will however not work for my current situation.

The goal of this macro will be to get the user to type the shortcut that his specific app uses for an internal command. That shortcut must be able to be used in my other submacro's to trigger the app shortcut, but i dont want to preset the specific to the defualt shortcut of the App, since the App let's the user customize its shortcuts. So I want to ask the user what shortcut the macro will be using.

For example the default shortcut for the App for closing it's project file might be ⌘⌥W, while the user might have changed it to something like ⌘W and not the system default

Hey Gideon,

Go to your “Type the Return Character” action.

Right-Click on it and select “Copy as XML”.

Paste that into BBEdit (or equivalent) and look it over.

By testing you can figure out what the modifier keys are, and you can use this excellent freebie utility to detect the codes for keystrokes:

Key Codes

Once you understand what the codes are you can find/replace in the XML and then run it like this:

Execute an AppleScript.kmactions (1.4 KB)