Problem creating shortcut for text string that includes the escape key

I'd like to create shortcuts for the following key/text strings, to be used within Mathematica:

esc elem esc (where "esc" is the escape key, not the literal text string)

and:

\[Element]

I've tried both to the best of my ability (see attached screenshots), yet the first doesn't work, and the second works inconsistently. The former gives me "lm" proceeded and followed by a space, while the latter sometimes works, and sometimes breaks the string between two lines (the break point is also not consistent).

And here's what I get:

Hi @theorist,

Is there any reason that the text needs to be inserted by typing, as opposed to pasting? Pasting is generally a much more reliable way of inserting text, so unless Mathematica specifically requires typing, I would try changing that first and see if it makes a difference. If the text does have to be inserted by typing, you might try using Set Action Delay to slow down the characters being inserted and give them more time to finish being typed out:

1 Like

Thanks @gglick, that solved it! I had no idea about the difference between pasting and typing until you mentioned it. Indeed, I thought typing simple meant ‘insert typed text’, but now I understand it means ‘type out the letters in sequence’. [BTW, I tried the set delay with the first macro, and I got different results depending on the delay, but none of them worked.]

1 Like