How can I use the Enter Key inside of a Typed String?

Is there a way to include the Enter key in a typed string?

I have a series of short hand strings that are similar and of different lengths.

I'd like to type -7- 'Enter' where the Enter key is the last character of the string.
Does that question make sense?

I currently have them all ending with and asterisk,
but the Enter key would feel more natural to type.

Have you tried literally typing the ENTER or RETURN key where you want it in the typed string?

Thanks - I'm trying to include the Enter key in the typed string (as a trigger), not as part of the "Insert Text"

OK, doing that in a TRIGGER is completely different.

You can use this RegEx:

The "\R" at the end will match any end of line char, like CR and LF.

However, I have to ask why use an ENTER as part of your Typed Sting Trigger?
That might not always work as expected, depending on the app.

I'd suggest a non-Regex Typed string like this:
where 𝍖 is a SPACE.

The semicolon at the start minimized false triggers.

That's not working either.

I'm using 'Enter' because I'm trying to enter codes with just the keypad - the left hand is busy setting off midi triggers.
My hope is not to need to move my hands at all. The enter key has the feel of being 'done' (like the '=' on a calculator) so it just feels like the natural end to all the codes.
Using * at the end works, but it's an unnatural hand motion

Did you configure the trigger as a "regular expression matches"?
It works fo me. BTW, you do NOT type the backslashes when using.
Just type:
-7- and then the ENTER key.

In Pages, that solution works for the Return key, but not for Enter.
But - I'm trying to get it to work inside Finale, and I don't think it recognizes any of this.

Can I ask a different question?
Another thought I had was to trigger the asterisk with a midi pedal to end each code. But, that isn't registering as part of the the typed string.

I would type -7-* where the * is a midi trigger.
It currently puts the asterisk where it should be, but won't trigger the macro.

any ideas?

Enter is actually Control-C \u0003 ETX “End of Text”, which you can match with the regex:


Note that - should not be backquoted in a regex outside a character class (eg [a-z] or [\-az]).

Also note that \R wont match Enter = Control-C.

1 Like

Thanks, Peter. Good to know. Obviously Regex matching in a Trigger Typed String is different than matching a normal string.

While we are here, what is the Regex for matching the RETURN key?

Escaping the dash \- seems to work fine in my Regex101 test:

Note that it says:

I have found it is easier to always escape metacharacters than to remember the rules of when it is necessary, and when it is not necessary. It does NOT seem to harm the match to always escape them.

I've redesigned the shorthand to not include '0' so I can use it as the de facto ENTER key.
Finale didn't want to accept the real ENTER key in this situation, and well, who am I to argue?

Thanks for everyone's help!

The regex for the return key is \r. \R would presumably work as well.

The problem with this is that \ does not just escape all characters - for some characters it makes them mean something.

So while you're probably safe with the using \- in place of -, it's not guaranteed. Since - is just a regular character like any other character, it is not impossible that a future change or some extension would make \- mean something else in the same way that r is a regular character and \r means something else.

So while I understand the simplicity of just escaping everything, it has its own risks, especially with potential future compatibility.

The ICU documentation is explicit on which characters must be quoted, but not clear on what can safely be quoted.

/ quotes the following character. Characters outside of sets that must be quoted to be treated as literals are * ? + [ ( ) { } ^ $ | \ .. Characters [inside sets] that must be quoted to be treated as literals are [ ] \ and depending on the context are - &.

As an aside, I often use the more literal nature of inside sets to avoid excess use of backslash which otherwise can lead to Leaning Toothpick Syndrome by using regex such as [*] or [$].

Anyway, as long as you're comfortable with that possible future compatibility, it should be safe enough to just quote everything non-alphanumeric.

1 Like

I use double dots to end a string trigger, for instance, I type “date..” to insert a date, “51..” to paste the answer for quiz 5, question 1, “add.." to paste my address, "km.." for keyboard maestro.
double dots are rarely used in my writing(typing), so its been working great for me.
The keypad has the dot. Maybe this option is worth considering for you as well.

I tried the dot - But I'm aiming for speed when typing these codes, and the ring finger on my right hand is not co-operating! It tends to hit every key but the one I tell it to hit.
I've settled on a similar idea to your suggestion but using '0' as the final character.

1 Like

Actually the dash - is NOT like any other character. It is a metacharacter used in ranges.

That is NOT what I do.
I only escape metacharacters when I need to match those characters as a literal.
And, since "-" is already a metacharacter, I think it is highly unlikely that a NEW metachar of \- would be added to the Regex language.

I find that harder to read, and requires more typing.
IMO, it is very clear that \* means the literal character *
Your use of [*] causes me to have to stop and think about what does that actually mean.

There are a small number of metacharacters that use the backslash -- and all of them are letters.
So, when I see any of these I know immediately it refers to the literal characters:
\\ \. \* \- \+ \[ \] \( \)

As a matter of curiousity, I played around with the Typed String Trigger, and found this interesting combination:
\-7\-(\R|\u0003|0| |\.\.)

This allows the macro to be triggered by the Typed String:

followed by any one of these:

  • RETURN key
  • ENTER key
  • 0
  • SPACE key
  • ..

Have fun!


This is great - it works in every app but the one I need it to!!
At least not the ENTER key. But the 0 or .. work great.
(I'm trying to enter chords in to Finale, which isn't really text)

Thanks for everyone's help. I've learned some new stuff!

1 Like