How do you set just a Tab key, to trigger a text expansion?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AHKExplorer
Posts: 20
Joined: 19 May 2019, 17:04

How do you set just a Tab key, to trigger a text expansion?

Post by AHKExplorer » 19 May 2019, 17:10

Hi,

I'm just using AutoHotKey right now, for text expansion. I searched google for 'autohotkey single trigger key' and similar searches, but cannot find the answer to this.

I want to use ONLY the <tab> key to trigger a text expansion.

So if I have wt defined thus:

::wt::What the...?

, I'd want to type

wt <tab>, and ahk will return the full text expansion.

But if I type wt <ENTER> or wt <space> or wat <period(.)>, I want ahk to do NOTHING.

How do we restrict the trigger key, to ONLY the <tab> key?

Also, how do we put a carriage return/line feed into the text expansion? So if we want for 'wt' to represent

what
the
heck
is
going
on
?

, how to we move each word to the next line?



Thanks,

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: How do you set just a Tab key, to trigger a text expansion?

Post by gregster » 19 May 2019, 22:19

AHKExplorer wrote:
19 May 2019, 17:10
How do we restrict the trigger key, to ONLY the <tab> key?
You can set the allowed end characters for all hotstrings of a script with the #Hotstring directive: https://www.autohotkey.com/docs/Hotstrings.htm#EndChars
For special characters like tab, you will need the corresponding escape sequence, in this case `t

Code: Select all

#Hotstring EndChars `t
:o:wt::What the...?
To omit the tab character at the end of the replaced text, add the o option, like I did above.
AHKExplorer wrote:
19 May 2019, 17:10
Also, how do we put a carriage return/line feed into the text expansion? So if we want for 'wt' to represent
You can use a continuation section

Code: Select all

:o:wt2::
(
what
the
heck
is
going
on
?
)
You can probably also use newline character `n (and/or a carriage return `r) directly with the hotstring, if the overall replacement text isn't to long:

Code: Select all

:o:wt3::what`nthe`nheck`nis`ngoing`non`n?

AHKExplorer
Posts: 20
Joined: 19 May 2019, 17:04

Re: How do you set just a Tab key, to trigger a text expansion?

Post by AHKExplorer » 19 May 2019, 23:10

Thanks, Gregster. I'm surprised that it's necessary to specify the tab character in order to exclude the others, since those trigger characters are automatic. I guess I was expecting an EXCLUDE section for characters you don't want.

In other words, if the entire ahk code is

::hw::Hello World
::wt::What the...?


, the default trigger will be <tab>, period, space, <enter> and maybe some others.

Anyway, that's neither here nor there. If the #Hotstring directive does the trick, that's good enough.

Thanks for all the samples to start with, that's perfect.


Regards,

gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: How do you set just a Tab key, to trigger a text expansion?

Post by gregster » 19 May 2019, 23:21

Right, there is no exclude option available for this.
https://autohotkey.com/docs/Hotstrings.htm#EndChars wrote:Ending characters initially consist of the following: -()[]{}':;"/\,.?!`n `t (note that `n is Enter, `t is Tab, and there is a plain space between `n and `t).


User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: How do you set just a Tab key, to trigger a text expansion?

Post by jeeswg » 20 May 2019, 04:29

There's also the * option:
Hotstrings - Definition & Usage | AutoHotkey
https://autohotkey.com/docs/Hotstrings.htm#Options
* (asterisk): An ending character (e.g. Space, ., or Enter) is not required to trigger the hotstring.
Two examples:

Code: Select all

:*:wt`t::What the...?

:*:wt2`t::
(
what
the
heck
is
going
on
?
)
*/
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Post Reply

Return to “Ask for Help (v1)”