Is There a Condition That Can Trigger After I Type Any Single Character?

I frequently use superscript in PowerPoint. Typically, I only need to superscript a single character. I'd thus like to create a Macro that automatically deactivates the superscript font after I type one character. I.e., I would like to create a Macro does the following:

  1. Simulate the superscript shortcut
  2. Wait until a single character is typed
  3. Simulate the superscript shortcut again (this deactivates superscript).

Using my best guess of what might mean "detect a single typed character", I tried the following, and there are two problems: (1) It doesn't work as intended—it doesn't wait for me to type a character, and instead immediately activates the font change for all the characters in the current word (2) For some reason, it is activating subscript (CTRL =) instead of superscript (CTRL SHIFT =)—it's as if it's not properly simulating the SHIFT part of the keystroke.

Note: Problem #2 is present even if I disable the 2nd action, below. If I apply CTRL SHIFT = directly with the keyboard, the superscript activates properly.

[In case you're confused why I'm using CTRL instead of CMD: The Mac PowerPoint shortcuts for subscript and superscript used to be CMD = and CMD SHIFT =, respectively. But, in about 2019, MS changed them to CTRL to increase parity with the Windows version of PowerPoint. Unfortunately, they have not updated their documentation to reflect this.]

Instead of waiting for you to type the subscript character, I'd suggest using a KM Typed String trigger.

Something like this:

MACRO: Enter PowerPoint 365 Superscript Using Typed String Trigger [Example]

Please let us know if this works for you.

NOTE:

  • This should have been a very simple macro using the PowerPoint 365 keyboard shortcut to set/apply Superscript. Unfortunately, for some bizzare reason the shortcut that works manually does NOT work when issued by a KM Type Keystroke Action:

image

1 Like

Thanks so much for putting in all this work! It works beautifully for alphanumeric strings. [I modified the trigger so all I have to type is "`,.`"] And it's really nice that it handles more than one character! Given the latter, I'd like to use it not only for "+" and "–" but also for forms like "3+" or "2–" (these are used for ion charges) or "–2" (numerical exponent), where the "–" is entered as an en-dash, i.e., OPT followed by -. Unfortunately, this macro doesn't seem to work on any of those.

I'd also like to adapt it for subscripts. Should I simply replace all instances of "superscript" with "subscript"? Or, since for subscripts KM is able to follow the issued KB action, is there a simpler alternative?

I appreciate the convenience of a shorter typed string, but that one my lead to a lot of false positives, if it is simply a "comma period". It's up to you of course, and you'll soon find out if it is a problem or not.

You can change the trigger to:
;ss\.[\w\+\-–]+

Simply put all characters you want to allow between the square brackets.
\w means word characters, which are all letters, numbers, and an underscore.
\+ is the literal plus character, and \- is the literal dash/hyphen character.

If you want to allow all characters, except a SPACE, you could use:
;ss\.[^ ]+

Note that there is a SPACE character at the very end.

I tried your second option (modified with my preferred shortcut*):

,.[^ ]+

I find it works with alphanumerics, but doesn't work when the superscript contains either a + or –

With the latter characters, I get the following error message:

*I'm planning to use it while teaching an online chemistry course. I need a very quick way to enter exponents and ionic charges, and don't anticipate having that combination of characters when convering the material.

Another option would be to use a typed string trigger to trigger a user input prompt.

Not sure if I got the syntax for Powerpoint right, as I don't use it. I find typed string triggers for prompts very useful. You can simply confirm your entry with enter.
I use them a lot for writing LaTeX. The only problem that I have with Keyboard Maestro in this context is that it can't handle nested prompts. For your case, that should not be necessary though.

Sorry, I forgot to change the KM Search Regex that extracts the script characters.

Just updated OP and Macro with a major update.

Please give this a try. Delete the original macro before importing the new version.

If you want to change the Typed String Trigger, you will also have to change other parts of the Macro, as well as the AppleScript, to match.

Hi JMichaelTX. I deleted the old Macro, and tried the new one without making any modifications (just imported and activated it) and I'm afraid it doesn't work at all, even on normal characters. E.g., if I type the following, followed by a space, nothing happens:

Hello;ss123

Hi Ph_Hem. Could you explain how I would use your Macro? Am I supposed to type in "Superscript" and then paste the text that I want superscripted?

You need to add a period after the ss:
;ss.123

I

Ahh, sorry, I wasn't really clear.
You would simply type a certain string, that triggers the macro. I personally like to use a "." prefix before typed strings, because in regular text writing, you would usually add a space after punctuation. Writing ".sup" could be such a trigger. A prompt will pop up in which the text field is automatically enabled. Technically, you don't need to lift your fingers from the keyboard.
Your entry in the prompt will be saved in the variablen that can then be inserted into your macro in which ever way is most conducive to the use with PowerPoint.