Produce a Representative String for a Command-Key Keyboard Shortcut

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
;cmd
;shift
;opt
;ctl

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.

https://www.emacswiki.org/emacs/KeyChord

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?

For some reason that I cannot explain, your explanation is perfectly clear and now I realize exactly what he wants. (Although we still aren't sure which combinations of modifiers he is interested in. And we don't know which keys he wants the modifiers to work with.)

==BELIEVE IT OR NOT, I think I have a solution!!!== But I need someone who knows AppleScript to help a little bit. I need to be able to turn the modifier keys completely off, using an AppleScript command, doing in AppleScript what you can see here: (turning these four options off).

I've done some preliminary testing, and it works for ASCII keys, and I think I can make it work for Hotkeys also, without hundreds of triggers. All I would need is a single trigger to cover all the ASCII keys, that looks like this:

Plus I would need to add UNMODIFIED hotkey triggers for the remaining USB keyboard keys (about two dozen keys?) So I wouldn't need a hotkey for both CMD-End and End, just for End, because the modifiers would be detected independently, after the KM engine captured the End key (and re-enabled the modifiers.)

If you don't understand my method, don't worry about it. But if someone can give me the AppleScript that I requested, I think I can handle the rest.

Here's a work in progress, that works.

You type two commas to initiate the substitution and then a 'c' for the Command key symbol, 'o' for Option key, 's' for Shift and/or 'z' for Control, followed by anything else to complete the trigger.

The macro will print the equivalent symbol in the order the macro looks for it. That maintains consistency in the overall text (Shift will always appear before Control, for example).

I thought this would work with a simple Switch action (which, if I'm reading the docs right, evaluates every case) but it doesn't. So I've used four If actions.

Anyway, as it is, it lets you use simple letters to build a key chord and print its symbols.

Update: The new version looks at the front window's title to see if you're writing HTML and, if so, uses the unicode for these symbols. Otherwise, it uses the symbols.

Another Update: The latest version builds the chord in a local variable so only one Insert Text by Pasting is used, making insertion faster.

[Test] Enter Modifier Key Symbols.kmmacros (14 KB)

1 Like

There's always this:

https://robservatory.com/a-much-improved-special-character-palette/

or this:

1 Like

Sorry — late and perhaps not apt, but I use KeyCodes for this.

I use the symbol strings in a database tracking what I've always called Keychords, because I think Keychords is more precise and easier to use than "keyboard shortcuts". I use a Moonlander programmable keyboard, which allows four keychords per key per layer without any modifier keys. It's a lot to keep track of.