Hotstring ending character Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mixx

Hotstring ending character

11 Sep 2018, 08:33

Hi,

I am new to AHK and using v1.1.30.00.

I managed to define a few hotstrings but they all have the problem that the ending character is eaten on execution:

::btw:: Send by the way

If I type, say, "btw." I get "by the way" instead of "by the way." (with the period). Even if I

:O0:btw:: Send by the way

I don't ghet what I want. Or when I use

#Hotstring O0

which should really help. What am I newbie doing wrong?

Thanks, Mixx
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Hotstring ending character  Topic is solved

11 Sep 2018, 09:04

You could use this

Code: Select all

string := "by the way."
::btw:: Send %string%
Mixx

Re: Hotstring ending character

11 Sep 2018, 11:45

Thanks, I thought of that. The major issue being that you need a separate definition for each ending character.

There must be a better way. Besides, the O0 option doesn't work. And it should be the default, if I read the manual correctly.

Is this a bug, then?
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: Hotstring ending character

11 Sep 2018, 11:57

By default, the ending character is included with the hotkey. That is, if you exclude send. ::btw::by the way works as you want.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Hotstring ending character

11 Sep 2018, 12:15

what is the actual full script ure using? because i can tell u, it for sure isnt ::btw:: Send by the way. That would produce the literal Send by the way(yes, with the space in front), and not execute the send command.
If u want it to, use the X hotstring flag: :X:btw::Send by the way. ::btw::by the way should also work as expected.
The endchar getting swallowed might be the result of your editor, as the hotstrings do some backspacing. Test it in plain notepad.
Mixx

Re: Hotstring ending character

11 Sep 2018, 15:54

Thank you ver much, sorted. I am learning AHK and for some reason I thought I always need a "Send". These hotstrings work now.

But this one doesn't:

Code: Select all

::#d::
    Send %A_YYYY%-%A_MM%-%A_DD%
return
in the sense that this one does swallow the ending character.

Please help me out with this one and I can do 80% of what I wanted from AHK.

Thanks, Mixx
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Hotstring ending character

11 Sep 2018, 17:39

Code: Select all

:XB0:#d::sendText(A_YYYY "-" A_MM "-" A_DD) ; X - call function, B0 - turn off backspacing

sendText(str) {
	hsLen := StrLen(RegExReplace(A_ThisHotkey, ":[^:]*:|(.*)", "$1")) ; returns StrLen of hotstring that triggered it, ie StrLen("#d") in ":XB0:#d"
	SendInput % Format("{Left}{BS {1:}}{2:}{Right}", hsLen, str) ; manual backspace the correct number of chars, keep the end char and finally jump over it 
}
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Hotstring ending character

11 Sep 2018, 18:00

Mixx wrote:this one doesn't in the sense that this one does swallow the ending character.
You need to see the difference between auto-replacing hotstrings and non-auto-replacing hotstrings. The first do keep the end character and look like the single line hotstrings with just replacement text. The latter are the ones with an x option or spanning multiple lines to execute some script (like Send or anything else), and don't output anything by default other than the backspaces to remove the triggering string. Luckily there's the A_EndChar variable that contains the actual end char used to complete the hotstring.

E.g: :X:#d::Send %A_YYYY%-%A_MM%-%A_DD%%A_EndChar%
Mixx

Re: Hotstring ending character

12 Sep 2018, 03:35

Thanks a million, Nextron, that gets me going for now!

Thanks, Mixx

PS: From the perspective of a noob, AHK seems to be very tricky. I know, it is powerful, too.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 87 guests