I don't know what to call this request

And I don't know if this is a good idea, but I'd like to try it if KM can do that.

I would like KM to react differently after the letter “J” is pressed.

  1. If any other letter follows “J,” nothing happens. So you can type ‘job’ or “jacket.”

  2. However, if a second “J” is typed very shortly after the first “J,” something else is triggered. The timing needs to be defined. KM would have to wait for the letter following the first “J” to determine whether “J” is typed or not.

Is this possible? Thanks!

Can you not use a typed string trigger for jj?

That would be something else :slight_smile:

“J” should only be typed if no other “J” follows it.

I'm not sure why that's something else? If you type jj then your macro will fire, optionally deleting both the js in the trigger. If you type jo or ja the macro doesn't fire and you can continue to job or jacket.

It is best if you are in a context, eg a text box, where deletion is predictable -- but your continuing to type a word does imply that.

Otherwise you're looking at a hot key J that swallows the character, disables itself, and enables a macro with hot key triggers for every possible next character. That second macro does something if the trigger is J or types J%TriggerValue% for anything else, disables itself, enables the first macro. You'll also have to store whether the first J was lower- or upper-case, to get that right in the second macro.

Yes, probably something like that. And lowercase only.

“jj” means don't type anything, but trigger something else.

Does that mean it's possible? Unfortunately, I have no idea how to do that.

Try the typed string trigger first -- in what way doesn't it do what you want?

I am confused.
Is it important for you that a typed j never appears visually until another non-j-character is typed?
It is not good enough that a typed j is not left as text if part of a typed string jj?

If the latter is good enough, what? @Nige_S suggests shuld do it

Nige_S :slight_smile: , you're definitely a lot smarter than I am. I actually mean that as a compliment, although given how dumb I am, that's not really saying much.

It's not the same thing whether you delete two characters after typing them or whether those two characters were never typed.

What do you want to happen when a j is typed and not followed by anything?

Nothing :slight_smile:
If nothing follows the “j” or if another character follows, everything remains “normal.”

Only if a second “j” follows something else should happen, without anything being typed. This is because the macro should also work safely in a non-text field.

Of course it isn't. And it's not the same thing if I type a snarky post then cancel it or never type it at all.

But it's the same result as far as you're concerned -- in neither case do you see my snark.

So what is the actual, rather than philosophical, problem with using a typed string trigger? Because it is a hell of a lot easier than setting up a macro with 100+ hot key triggers!

"Normal" would otherwise be a j is typed. But the way you've been describing it, it sounds like you want normal to be j is not typed if not followed by anything (other than another j)?

@Nige_S Sorry, I didn't mean that to sound snarky. I really didn't. If that's how it came across to you, I apologize.

I was taught on this forum never to use string triggers in non-text fields. Because deleting characters can have serious consequences under certain circumstances. :man_shrugging:

And if a macro like that isn't really feasible, then so be it. I'm asking because I don't know.

I don’t think you were snarky. I just think he used snarkiness as an example, and he wasn’t meaning anything by it.

@Alexander I guess what I want is nonsense.

I imagine that a “j” would always be typed, unless a second ‘j’ follows the first one very quickly. I don't know; so KM has to wait to see what comes next before typing the first “j.”

Guys, that was just a question. Apparently, it's not that simple :slight_smile:

Hopefully :slight_smile:

How close is this getting you?

(To function as intended macro A should nominally be enabled, macro B nominally disabled)

Macro Images

ΚΜ TestForOthers Macros.kmmacros (7.8 KB)

EDIT: Here my attempt at meeting what you've been describing is up again

@Alexander Thank you so much for your efforts. I'm really looking forward to trying that out tomorrow. But I have to go to bed now. I'll let you know :slight_smile:

Basically, no. And even if you work around the no, it will cause problems.

If you type the first 'j', before you type anything else, you have two choices:

Since you haven't typed another character or not typed another character yet, one of those things has to happen.

When you type 'o' or 'j' later, the first thing cannot change. Keyboard Maestro does not know in advance what you are going to type, so the second character cannot affect how the first character is handled.

You can't both have the 'j' typed if you plan to follow it with an 'o' and also have to 'j' not typed if you plan to follow it with a 'j', without knowing in advance what your next character is going to be.

If you swallow the key (as would be required for the 'j' never appearing if you might type 'jj', then there is no good way to un-swallow the 'j' later if you type something else, because by then you have typed something else. The characters are now out of order. Attempting to put them back in order doesn't work if you might also have typed another character (like the 'b' in 'job').

Understanding why this is the case requires understanding how the system processes the input keys and the event queue.

I actually missed this reply of yours when constructing the macro above. My macro above followed the idea that a j should never be typed, unless it is followed by another non-j character, as I read you further up. The highlighted part is what allows for the macro not to read into the future (so no grandchildren paradoxical weirdness here, haha!)

This updated version of the macro might get close to your described functionality:

  • Single "j" is typed — gets typed after a delay of 0.5 seconds
  • "j" followed by any other typed character — insert a j before the other typed character. Choose to do this by selecting (shift + left arrow) the typed other-character and overwriting it, instead of using a delete, something that should be a safer operation if you ever use this macro while not in a text field.
  • "j" directly followed by another "j", within 0.5 seconds — No "j" is typed, and continues to whatever you've placed under the initial group of macro A

As this is a macro that is interfering with how you type it, it is of course important to test it to see if it is stable enough for your needs. But it seems okay stable, and I have been able to write this whole post with it switched on.

  • The 0.5 second delay can of course be set to another value you desire, but note that the pause at the end of macro B should be set to this same value. This is needed to make sure the "The j-macro B" semaphore will prevent macro A from inserting an extra "j" after the fact, if any other character got detected by macro B.

  • And again, macro A should nominally be enabled, macro B nominally disabled

ΚΜ TestForOthers Macros.kmmacros (13 KB)

Macro images