0

AutoHotKey v. 1.1.33.09. Windows 10, Firefox, Edge, Chrome, multiple applications

I have several lengthy email addresses associated with some non-profit work I do. I am creating shortcut keystrokes in an autohotkey script for each email address, phone number, and mailing address to speed form filling.

There are unwanted trailing single spaces being produced in the output string which forces me to manually type a backspace in order to move on in the form that is being filled.

How to elegantly eliminate these spaces?

::.1::john.doe1@myhost.com
return
::.2::john.doe2@myhost.com
return
::.ad::1234 Address Blvd, Anytown, USA 99999-1234
return
::.p::1-800-555-5555
return

note: In the examples below the underscore symbol _ represents an unwanted trailing space.

.1[enter] returns john.doe1@myhost.com_

.2[enter] returns john.doe2@myhost.com_

.ad[enter] returns 1234 Address Blvd, Anytown, USA 9999-1234_

.p[enter] returns 1-800-555-5555_

  • I searched the AutoHotKey website Quick Reference and FAQs. The link to the AutoHotKey forum was a dead link. I have searched the StackOverflow forum with keywords 'AutoHotKeys', 'trailing' and 'space' and found some similar requests. All responses I found delt with far more complex user requirements with similarly complex solutions. I did not find any answers related to this simple requirement. I have tried inserting backspace to the scripts with no effect. – ronlee67 May 20 '21 at 00:13

1 Answers1

1

The O option(docs) should do the trick for you:

O: Omit the ending character of auto-replace hotstrings when the replacement is produced. This is useful when you want a hotstring to be kept unambiguous by still requiring an ending character, but don't actually want the ending character to be shown on the screen. For example, if :o:ar::aristocrat is a hotstring, typing "ar" followed by the spacebar will produce "aristocrat" with no trailing space, which allows you to make the word plural or possessive without having to press Backspace. Use O0 (the letter O followed by a zero) to turn this option back off.

So your script would be:

:O:.1::john.doe1@myhost.com
:O:.2::john.doe2@myhost.com
:O:.ad::1234 Address Blvd, Anytown, USA 99999-1234
:O:.p::1-800-555-5555

Note that I also removed the redundant returns.
They're only needed if you're not writing one-liners.

0x464e
  • 5,948
  • 1
  • 12
  • 17
  • While this is a very plausible answer, OP states in the question that they are using the enter key to produce the ending character. This would probably be the solution if OP was using a space as the ending character. – Charlie Armstrong May 20 '21 at 00:02
  • Enter is an ending character by default. This works just fine. Though I really don't know how OP got the trailing space in there if they were using enter as the ending character. But in any case, the `O` option should be the solution. – 0x464e May 20 '21 at 00:23
  • That was my point. The `O` option would only remove the trailing space if the space was produced as an ending character. This answer could still be useful to future visitors, though, and it's also possible OP has omitted some key information from their question. – Charlie Armstrong May 20 '21 at 00:43
  • 1
    Right, yeah I see what you mean. Lets see what they'll say when they see this. – 0x464e May 20 '21 at 00:46
  • Problem 100% resolved thanks to your excellent responses. I added the o option as suggested. I also removed the return codes. Now the coding is much cleaner. – ronlee67 May 21 '21 at 02:32