'AUTOHOTKEY Hotstrings with overlapping abbreviations
I wish to create a hotstring "@@" for my email address, and another "@@@" for my full postal address. I have created a script that works when the third hotstring character differs from the second, but can't get it to work for my preferred "@@@" hotstring.
My working example uses "@@" for the email, and "@@1" for address, where the "1" needs to be entered within 0.7 seconds of entering "@@":
:*:@@::
keywait 1, D T 0.7
if errorlevel = 1
{
send {backspace}[email protected]
}
else
Send, {backspace}Mr.Benn, 52 Festive Road, London
return
Solution 1:[1]
I still have to work out why this answer works, but it appears to work as wished for:
:*:@@::
keywait @, U T 0.7
keywait @, D T 0.7
if errorlevel = 1
{
send {backspace}[email protected]
}
else
Send, {backspace}Mr.Benn, 52 Festive Road, London
return
Solution 2:[2]
Something to bear in mind is that the asterisk in the first set of colons means to not wait for an end character, like space or return to fire (see docs https://www.autohotkey.com/docs/Hotstrings.htm for full list).
A more elegant solution might be something like:
::@@::[email protected]
:*:@@@::Mr Random, 123 Some St, Anytown, 012345
I personally prefer using a prefix character in my hotstrings like "*" when sending a full string and not just a typo fix. Example:
:*:*tysm::thank you so much
In my decade of experience with AHK this prevents accidentally creating a hotstring that replaces something you didn't think about on initially writing the script (something always gets forgotten).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | thescoop |
Solution 2 |