basic text replacement Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

basic text replacement

Post by geoffh » 08 Aug 2022, 11:40

Hi,

I am merely trying to use AHK for basic text replacement.

All was fine, I have a trigger key of hash (#) for example.....

#a would generate my address

#e my email address

etc. etc. Anyway, I now wished to generate: Please Enter Code #123 .... where the last 3 digits will vary

My Replacement line is :*:#u:: Please Enter Code #123 . However, what comes out is Please Enter Code 123

- the # is missing.

How may I get round this (I don't want to change the trigger from a #)

Grateful for any suggestions - many thanks.

Geoff H.
Last edited by gregster on 08 Aug 2022, 11:49, edited 1 time in total.
Reason: Added provisional topic name. Feel free to change it to something more appropriate.

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: basic text replacement

Post by RussF » 08 Aug 2022, 12:17

Try:

Code: Select all

:*R:#u::Please enter Code #123
You have to send the data in raw mode or else the #1 is interpreted as WinKey-1.

Russ

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: basic text replacement

Post by geoffh » 09 Aug 2022, 10:27

Russ, many thanks for a speedy reply.

I looked up "Raw mode" but couldn't see what I was to do in a text file, i.e. do you know what I should have entered into my text file, instead of....

:*R:#u::Please enter Code #123

..... in order to get the desired effect?

Thanks once again.

Best Regards.

Geoff H.

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: basic text replacement

Post by geoffh » 09 Aug 2022, 10:55

Hi again Russ,

Further to my last message, I have been "playing about" with AHK and find I can get the desired effect by using brackets, i.e.

Instead of.....

:*:#u::Please enter Code: #123

I enter this....

:*:#u::
(
Please enter Code: #123
)

..... which works a treat.

Again, thanks very much for your help & support, it would have taken me MUCH longer to get there without your response :D :D

Best Regards.

Geoff H.

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: basic text replacement

Post by RussF » 09 Aug 2022, 11:13

geoffh wrote: I looked up "Raw mode" but couldn't see what I was to do in a text file, i.e. do you know what I should have entered into my text file, instead of....
:*R:#u::Please enter Code #123
..... in order to get the desired effect?
When you want the characters "Please enter Code #123" in your text, simply type #u. That's the actual # character - NOT the Win key. The "R" in the definition means that the "#" in your replacement string will be typed instead of interpreted as the Win key. When I tried your original code, AHK was sending Win-1 to Windows which activates the first window in the stack of open windows. The "R" prevents that.
geoffh wrote: I enter this....
:*:#u::
(
Please enter Code: #123
)
..... which works a treat.
If it works, great, but is unnecessary. Since it is the last hotstring definition, the "Return" is implied, but if you add a definition after that one, you must put a "Return" after that definition, i.e.

Code: Select all

:*:#u::
(
Please enter Code: #123
)
Return
Russ

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: basic text replacement

Post by geoffh » 09 Aug 2022, 11:44

Yep, # is my trigger key, I have about a dozen "Text Replacements" set up.

However, going back to my example above, where I wanted to generate a "#", it did not work with

:*:#u::Please enter Code: #123

for exactly the reason you said.

When I modified it to

:*:#u::
(
Please enter Code: #123
)

- it worked, due to anything within the brackets being taken "as is".... the brackets themselves do not get displayed.

One other thing to mention, I have several other rows in my text file (which I Compile) following the "u" entry, WITHOUT any "Return" - but these all work fine.

Hope this helps others.

Best Regards.

Geoff H.

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: basic text replacement

Post by RussF » 09 Aug 2022, 11:49

Did you try my code below? It worked perfectly for me.

Code: Select all

:*R:#u::Please enter Code #123
Russ

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: basic text replacement

Post by geoffh » 09 Aug 2022, 11:53

BIG apologies, Russ... I hadn't spotted the "R" at the beginning of the Line : o - presumably the R indicates Raw?

Do you have/could you provide a link to the part of the AHK Documentation where that sits please (I failed miserably looking for this!!)

RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: basic text replacement  Topic is solved

Post by RussF » 09 Aug 2022, 12:15

No worries. You can find it here under Hotstrings/Options.

BTW, I just happened to notice while I was looking it up, that the option "T" (Text mode) in place of "R" (Raw mode) may be more reliable. I didn't see this before. Try both. Your mileage may vary.

Either one should work:

Code: Select all

:*R:#u::Please enter Code #123
; or
:*T:#u::Please enter Code #123
Russ

geoffh
Posts: 48
Joined: 25 Mar 2014, 10:01

Re: basic text replacement

Post by geoffh » 09 Aug 2022, 12:25

Once again, many many thanks - great stuff, REALLY helped..... :D :D

Post Reply

Return to “Ask for Help (v1)”