A bit more of the context and purpose might help to make the question slightly more easily intelligible.
Dictionary means KM dictionary ? (rather than, for example, JS or PY)
How are you going to use the key (strokes|commands|names|codes|???) ?
If you were going to make some scripted use of them, it might be the codes that you wanted. For other uses it might be printable strings, or names, or their bindings to something else, like KM macros.
Hello, yes, the link you sent me is part of the solution, thank you. A KM dictionary. Instead of manually specifying key commands in KM, key commands would be stored in a dictionary. To find the specific key command in a given situation, the dictionary's key would be referenced, with the key command loaded into a variable. The variable would then be used to execute it's self-contained key command.
I supposed key commands could be encoded with a delimiter for combination keys (e.g. command, option). This string could then be passed to AppleScript to "type" the command. It'd be nice to stay inside KM, tho. Am I missing a way to do that?
As @hello has said, you could use a Switch Case and depending on the result of the data retrieved from the Dictionary yes, Keyboard Maestro could type them. By this method the actual data saved in the Dictionary could be in whatever form you like as long as you know what it means.
The image below is assuming the data retrieved from the Dictionary is passed to a Variable first (to keep the example simple). But you could alter so that the Switch Case works directly with the Dictionary by using a Text condition (and using the correct Dictionary syntax) rather than a Variable Condition.
Cheers on your example - that does the selection. I'm looking encode the keystrokes themselves in a dictionary. I have 130 separate key commands in the macro, and I'm reading them in from a plist file, to keep them manageable. Is there a way to do that?
It would be a very tedious task to set up a Switch Case with 130 different outcomes... but it would be possible if this goal of getting Keyboard Maestro to type hot keys is the only way you can accomplish your task.
As it all seems a bit left field - I'm wondering if there might be a better way to achieve whatever you are trying to achieve?
I had a quick reread of the threads above and I don't think you've stated what you are ultimately trying to do - i.e. why you need to type these hot keys. Apologies if I missed that.
notsteve,
it is not just a matter of keys but also what application they apply to. So it is most likely you have to use Applescript to accomplish the sending of keys to the specific application. I'm sure there are Applescript experts here that can help you. Is those keys specific to one application only or multiple applications ?
Hello, all. I've finished my code here, and written an abstraction layer for sending key commands from KM. Key Commands can be defined dynamically, as tokens.
A second layer of abstract added through CSV files, which store key commands, their modifiers, command names, etc. All key commands are supported (e.g. separate L%R command modifiers, brightness, and such—except one hardware key…I don't remember which. Or, maybe it does.
It's a nice system if you send a lot of key commands from KM to other applications—it's much easier to define them in a PLIST or CSV file. And of course you can dynamically switch between files, or change key command values in real-time.
The code is encapsulated from my application, but some tweaks might be desirable to make it feel more like a native KM feature. Or, it might be fine-as is. Tho…some people might prefer a part of it to be an Action, which would be simple enough.
If someone wants to jump into this, I'm happy to send. I don't know if it would be helpful to post as-is.
Thank you to the folks here for their kindness, and for Peter being so accessible. Quite a nice community here.
Hi Zabobon, yes you're quite right, of course. The abstraction system solves this problem, collapsing a linear time algorithm to constant time; i.e., there are no comparison operations.
After some thought, any implementation of this idea is arbitrary. It's perhaps most helpful if I post a macro template, and an Action. (I haven't tested the action, but it's very simple.)