Insert Text (Type Over Text or Overwrite Text when Typing)

I spent the last half hour seeing if there was a hidden keyboard overwrite setting buried in macOS which I could use for a better solution, but there appears to be no such thing. Many apps have decided to implement their own overwrite mode in macOS as a result.

So I think my approach, despite being a little convoluted, is probably the best approach and worth finishing. However it's time for lunch.

So far it works only for three lowercase letters. Making it work for the other characters on the keyboard is mostly a matter of physical labour. Although I'm still not sure how to get it to work for capital letters, but I'm sure that will resolve itself.

Yes, I can get that to work.

I think your interpretation is probably right.

I have a solution for the SHIFT key. Let me start working on it now that I'm back from lunch.

I will assume that it's only the SHIFT key we are worried about here. For example I assume that CTRL-A will not be treated as an OVERWRITE character. Basically I will just worry about typable keys, not the strange ones in the ASCII table. Hmm, that makes me wonder what you want in the case of a RETURN key. Well, we can worry about that later.

Yeah that’s a good assumption. I wouldn’t expect modifier keys to trigger this behavior except for shift.

Does your solution for capital letters address when they are entire via the Caps Lock?

Yes. :slight_smile:

Still working on it.

I think it's working now. The strange thing I had to figure out is that the hot key triggers are upper and lowercase specific while the Switch action is not case specific. The Switch statement says it can work with regular expressions using the Match option, but for the life of me I couldn't get that to work.

To be honest I think I can do better before I post it. I should be able to cut the size of my macro in half by getting the Switch action to be case specific somehow.

Ok, here is the "A-C" template for your solution. There are several things I must bring to your attention.

  1. The RETURN key issue has not yet been addressed. There used to be a token called %Return% but that doesn't seem to be working now.
  2. I did not yet address the method for switching between INS and OVERWRITE. That's a trivial issue. Nor did I address the issue of how to tell which mode the user his in.
  3. I currently implemented only the keys A to C. The reason I did that is in case I have to make changes to all the keys as I improve my solution.
  4. The program correctly handles upper and lower case even when the CAPS LOCK key is pressed.
  5. I had to handle the CAPS LOCK situation manually because the %TriggerValue% token for uppercase A is "A" and at the same time it's also "A" for lowercase A. This is not good behaviour for KM in my opinion. I think we should make a feature request that KM respects the case of the key in the %TriggerValue% token. The name of this product is KEYBOARD Maestro and so it should handle keyboard keys accurately.
  6. I had to deactivate the group at the top of the macro to prevent the macro from invoking itself when it sends keys to the active app. Then of course I had to reactivate it at the end.
  7. If we agree that the is a good solution then I'm willing to manually insert the other ~70 keys into the macro. But someone may suggest a better methodology so I won't do that yet.
  8. It would be really handy if KM had a trigger for "any key" instead of for single keys only. Or even better, for keys in a range, like A-Z. And then we could find out which key was pressed using the %TriggerValue% token.

Overwrite.kmmacros (13 KB)

I think this simple macro should what you ask, except for:

This macro uses as Typed String Trigger with a RegEx pattern.
You must trigger the macro for each string you want to insert.
It will then insert the text you typed, and then forward delete the same number of characters.

It uses this typed string:
;i.+;

which has delimiters of ;i and ;

thus your typed text can NOT contain a semicolon (";")
If that is a requirement, then you will need to use a different character for the closing delimiter that will never be inserted.

The macro removes the delimiters, leaving only the text you want to insert.

Give it a try ONLY in text fields, text area, or text document, and let us know if this will work for you.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Overwrite (Replace) Forward Text.

**Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+**
(Macro was written & tested using KM 9.0d9 (Beta) on macOS 10.14.5 (Mojave))

#### DOWNLOAD Macro File:
<a class="attachment" href="/uploads/default/original/3X/9/8/983d9db489c5b18c571e59acd9077b1ffbc6895e.kmmacros">Overwrite (Replace) Forward Text..kmmacros</a>
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**  It also ==was uploaded with a trigger.==




---

### ReleaseNotes

Author.@JMichaelTX 

**PURPOSE:**

* **Overwrite Text Like MS Windows "Insert" Key**
   * The same number of characters are deleted forward of the text that is typed/inserted.

**HOW TO USE**

1. First, make sure you have followed instructions in the _Macro Setup_ below.
2. Trigger this macro.

**MACRO SETUP**

* **Carefully review the Release Notes and the Macro Actions**
  * Make sure you understand what the Macro will do.  
  * You are responsible for running the Macro, not me.  ??
.
**Make These Changes to this Macro**
1. IF DESIRED, revise the Typed String delimiters.
   * Current the Delimiters are:  `;i` and `;`
   * Everything you type between these Delimiters will be inserted
   * IF you change the Delimiters, then you ALSO MUST CHANGE the RegEx in magenta colored RegEx
2. Move this macro to a Macro Group that is only Active when you need this Macro.
3. ENABLE this Macro, and the Macro Group it is in.
.
* **REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:**
(all shown in the magenta color)
   * RegEx: Extract Text to Type from Macro Trigger 
     * Change ONLY IF you Changed the Typed String Trigger

**REQUIRES:**

1. **KM 8.2.4+**
2. **macOS 10.11.6 (El Capitan)+**

TAGS:  @RegEx @TypedString @Insert

USER SETTINGS:

* Any Action in _magenta color_ is designed to be changed by end-user

ACTION COLOR CODES

* To facilitate the reading, customizing, and maintenance of this macro,
      key Actions are colored as follows:
* GREEN   -- Key Comments designed to highlight main sections of macro
* MAGENTA -- Actions designed to be customized by user
* YELLOW  -- Primary Actions (usually the main purpose of the macro)
* ORANGE  -- Actions that permanently destroy Variables or Clipboards,
OR IF/THEN and PAUSE Actions


**==USE AT YOUR OWN RISK==**

* While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
* If you have any doubts or questions:
  * **Ask first**
  * Turn on the KM Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

---

<img src="/uploads/default/original/3X/3/8/382cd82a1e121ae81ee79c356c99aa588556133b.png" width="561" height="876">

Wow, I had no idea the string trigger could be a regular expression. That makes your solution very short and effective. Thanks for showing that solution. KM surprises me all the time.

Nevertheless, the original post had specific requirements like a toggle key to switch modes. My solution doesn't yet include a toggle key but I was saving that trivial feature for the end. He also requested a notification or signal that the insert mode was on. These things are possible with my solution. My solution could also support arrow keys to move left or right while in insert mode.

I just enjoyed the puzzle and enjoyed finding a solution. If the poster prefers your solution, that's fine.

Thank you both so much for these macros. They both work great, just differently. I learned a lot seeing the different implementation of the same idea. I'm still testing and working out which way I'll prefer to work, but thank you so much.

I'm honestly not that surprised by the succinct RegEx method. A number of macros I've needed have had simple solutions via RegEx. It is quite a powerful too. Learning a little bit of it with each one.

Thanks a lot!

You are welcome. There's probably a little bit of ego involved in coming up with the best or chosen solution. But none of us are snowflakes so a little competition is fine.