Produce a Representative String for a Command-Key Keyboard Shortcut

Is there an action that generate the string for a keystroke ?
I would type the keystroke, I would get the string "⌃⌘↑", say, on the clipboard.
I am new to this forum. So sorry if I ask for the obvious.

Virtually anything is possible.

Your request is slightly unusual. Most people want "shortcuts" that replace what they are typing (eg, "afk" turns into "away from keyboard".) You are asking for something a little different. You seem to want the new characters to go into the clipboard instead of being typed where the user is typing. if I'm reading your request correctly, this should work. If I'm misreading your request, please tell me what isn't right with the following solution...

This macro will expand the string afk into the system clipboard and delete the string from the field that the user is typing in. As far as I can tell, this is what you are asking for.

There are probably lots of other possible solutions. This is just one method. If you don't like this solution for any reason, let me know, and I may find another solution that meets your needs.

Sorry I did not correctly convey my intention.
I want to write documentation for shortcuts in a application.
I want a macro that generates the string representing the shortcut when I type the chorded keystroke(s] for the shortcut somehow as input to my macro. I gave an example with one keystroke but there may be two. But if I get a macro for one chorded keystroke I guess it is possible to adapt it for many, Thx.

If you show me the before and the after of your problem, rather than talking about macros or shortcuts, I might understand then. But the clarification above doesn't help me.

The input is the chorded keystroke, it is not a string, it is not a KM trigger. The output is the string that represents that keystroke. Something like “⌃⌘↑“ that could be pasted in the documentation of my application. That would save from the hassle of somehow typing characters that are not represented on the keyboard.

Maybe you are using such a macro to write KM documentation about triggers.

Thx for your help.

I’m not aware of KM being able to recognize modifier keys as a stand-alone trigger. However, Typinator can, and when you press a modifier key it can paste it for you. Is that what you’re trying to do?

None of his posts indicated what he wants his "chorded keystrokes" to be. He hasn't given any examples. So I have to assume he could use a hotkey as a trigger for the macro I proposed in the second post i this thread. All he would have to do is replace the string "away from keyboard" with "⌃⌘↑" and everything would meet his requirements as I understand them.

Yea I’m not really sure what “chorded key strokes” is either but I figured I’d take a stab at guessing. :sweat_smile:

It’s been a long day :crazy_face:

I'm willing to help anyone I can. I've spent over 8 hours helping some people. I won't give up yet. But @cognominal has to help me, too. I want to see specific examples of input and output. Or even better, he should try out my macro and tell me why it doesn't solve his problem. Here it is as I last described it:

This will set the clipboard to "⌃⌘↑" whenever the user presses those keys together.

Personally, I wouldn't bother to set the clipboard, I'd just insert the text into the current document.

Thx. But the very point of this one macro would be to avoid a KM hot key trigger for each of the possible combinations of keys unlike you suggest.
I would type a shortcut for my application somewhere thanks to KM and would get in return the string that would be pasted in my documentation to document the said shortcut. Maybe it is not currently possible/natural in KM so you instinctively try to reframe my problem. Or more probably, I am failing to make myself clear.

Anyway even if this particular issue is not solved, when I wake up tomorrow I will buy a license (edit: done). I certainly do not ask for 8 hours of support at that price. Also I think I can solve the problem by writing a vscode extension. Either way, I will use the macro only as many times I have shortcuts to document but I expect to learn much in the process.

I already have written some (clumsy) macros that have proven useful. In one month or two, I will have recouped the time spent learning KM.

Pardon my French. I am not a native speaker and I probably misuse the KM terminology. I have yet to read the KM doc in extenso and understand all of it.

Also you ask for the input and the output, but both expressed as a string, they are the same even if the input is the typing of a shortcut and the output the string that documents it.

Yes. You mostly got it. Except the modifier keys (I call them chording) are not triggers. I want one macro, that allow me to type a shortcut of my app and get the corresponding string for my documentation with the correct character for each modifier. I don’t care much how I will trigger the macro.

I have yet to figure out how to show the post I answer.

Why do you not want to show an example of that? I can't understand that explanation. If you show an example, I can probably understand it. Don't even mention the words, "macro", "trigger", or any KM mechanics at all. Just describe the problem using an example and then probably we can understand it.

Sorry, I have no idea what that means, either. Once again, if you show me what you actually want, showing me the actual input and output, rather than explaining how you want me to implement it, I would have a much higher chance of success.

You came pretty close to providing "an example" when you said this:

However my macro actually solved that problem. My macro allowed for a chorded keystroke, which is called a hotkey in KM, and the macro then created output that could be pasted into your application. My macro solved the example that you provided. If you can provide additional examples that my code cannot solve, please provide the examples. If you want me to understand, then provide examples, not explanations.

Use KeyCastr and create screenshots of the keyboard shortcuts that are being displayed. Optionally, save and rename the images to the keys in question.

By now, I'm also curious what a [quote="cognominal, post:5, topic:26764"]
chorded keystroke [/quote] is in this case :thinking:

That's one of the reasons I'm asking for an example rather than a description.

I believe what @cognominal wants is exactly what the Keyboard Maestro editor does when you define a hot key trigger: he wants to be able to type some keystroke combination and get a textual representation of it that can then be pasted into a document.

Unfortunately, I don't think Keyboard Maestro macros have a way of capturing keystrokes like this. @ALYB's suggestion of KeyCastr does the interpretation of keystrokes, but I suspect @cognominal wants text rather than an image.

I use textual representations of keystroke combinations in my writing quite often, and my solution is to have a series of text substitutions (initialing defined in TextExpander but now defined in Keyboard Maestro) for entering the symbols. Like this:

Type this To insert this

For example, here's my definition for ⌘:

This is more typing than what @cognominal (or I) would like, but it gets the job done. I would love to have a macro that does the job in one step.

1 Like

That's what I thought my macro did in post 9. That macro allows him to "type some keystroke combination and get a textual representation of it that can then be pasted into a document."

Thx @drdrang to clarify what I meant. I wish I expressed my needs more clearly. And thx again for providing a work around. Thx for everyone who tried to help.

The doc says one can programmatically record a macro
and that one can record a keystroke, that is maybe a way to do it.
I am not in front of my Mac so I can’t test it right now.

I did not remember where I picked the expression. Probably from emacs.

Or vscode

“Chords (two separate keypress actions) are described by separating the two keypresses with a space. For example, Ctrl+K Ctrl+C.”

So I even got that wrong confusing keypress and keychord. Facepalm.

Perhaps we can make progress by analyzing the problem beginning with the output. To simplify writing the documentation, I believe that Cognominal would like a simple way to type into his text the symbols for the common modifier key combinations. I'm guessing that he might need different combinations of eight modifier keys: Shift, Control, Option, Command, and the four arrow keys. If this is correct, then the number of different combinations is quite large. Needed outputs would include ⌘⌃⇧; ⌘⌃⌥⇧; ⌘⌥⇧; ⌃⇧; ⌘⇧; and many, many more.

If this describes the needed set of outputs, what macros and triggers might be needed to produce all of them? It would be cumbersome and hard to remember a different trigger to invoke a different macro for each of the hundreds (?) of different modifier key combinations.

One approach is creating a different macro for each of the desired individual modifier key symbols. If the symbols for eight modifier keys are needed, then eight different macros are needed. Drdrang has already suggested this idea, using the semicolon plus a few letters as the triggers for the different macros. He suggested that the trigger ;cmd would produce the text symbol ⌘. ;shift would produce the text symbol ⇧. ;opt would produce the text symbol ⌥. And so on. Eight is a workable number of macros, but the proposed triggers require a great deal of typing for most modifier key combinations. For example, to produce the text symbols for the key combination ⌘⌥⇧, triggering the three needed macros as described by Drdrang would require 14 key strokes. Of course, Drdrang's triggers could be shorter, at the risk of making them harder to remember.

I don't know if the optimum solution is possible in KM. Could we create a single macro with a single trigger to accomplish the production of the text symbols for all the possible modifier key combinations? Following in Drdrang's footsteps, suppose that the trigger is simply the semicolon. After the semicolon hot key trigger, could KM recognize the immediately following modifier key combination, and insert the equivalent text symbols as 'text by typing' into a document? Sleepy already described how to do this with a macro for a specific modifier key combination. I'm dreaming of a single macro that, after the hot key trigger, could translate the next keystroke or keystroke combination into its text symbol equivalent. That is, a single macro that can handle any and every subsequent keystroke or keystroke combination. Can Sleepy's example be modified to do this, or would it require a separate macro for every possible modifier key combination?