Capture a longer hotstring before a shorter one ?

Get help with using AutoHotkey and its commands and hotkeys
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Capture a longer hotstring before a shorter one ?

25 Sep 2017, 03:12

Is there a way to capture a longer hotstring before a shorter hotstring included in it is captured, by establishing a kind of precedence?
example:

Code: [Select all] [Download] GeSHi © Codebox Plus

::white house::the president in the white house
::white::the white snow

currently just writing "white" activates the hotstring ::white:: before it can be verified if we also have "house".
I do not know if it is possible to retard somehow the capture of a hotstring to see if there is more inclusive.
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 03:26

What I would like to achieve is a kind of hotstring hierarchy where a longer hotstring takes precedence over a shorter one before checking for a replacement.
It is the concept of precedence that I want to highlight as indicated in the manual: how is the hotstring Pn Directive actually used?
the following code does not work as I would like:

Code: [Select all] [Download] GeSHi © Codebox Plus

:P1:white house::the president in the white house
:P0:white::the white snow

maybe the syntax is incorrect, but I did not find any examples on it.
User avatar
Capn Odin
Posts: 1222
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 03:37

The syntax is correct, but it sets the "thread's" priority, which determines which other threads can interrupt it.

Edit: It may be more accurate to say, it determines which threads it can interrupt.
Please excuse my spelling I am dyslexic.
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 03:45

I understand, then it's not the Pn directive that should be used: but then how can one delay the triggering of a shorter hotstring if it is contained in a longer one?
User avatar
Capn Odin
Posts: 1222
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 04:23

The problem is that Space is a Ending Character meaning that by hitting space you are telling the script that a hotstring may have ended.

Try removing the Space from the end chars. (I have already removed it)

Code: [Select all] [Download] GeSHi © Codebox Plus

#Hotstring EndChars-()[]{}:;'"/\,.?!`n `t
You can execute the hotstring by typing any of the other end chars, e.g. Tab.
Please excuse my spelling I am dyslexic.
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 06:09

Tanks Capn Odin for the suggestion, I have tryed the code:

Code: [Select all] [Download] GeSHi © Codebox Plus

#Hotstring EndChars-()[]{}:;'"/\,.?!`n`t
::white house::the president in the white house
::white::the white snow

but I could not reproduce the operation as desired: there is no way to recognize the longest hotstring "white house".

Reasoning, I try to further generalize the problem.
There are cases where the final character does not influence the hotstring, as in the following case:

Code: [Select all] [Download] GeSHi © Codebox Plus

:?*:12345678::len8
:?*:345::len3

now I try: 0123456789
and what happens is that it activates immediately 345 without waiting to see if it will be fully present 12345678.
I wonder if there is a way to tell the system to give priority to hotstring longer than the shorter ones.
I suppose it should be a high level directive , start with #, that influences the way AHK works.
User avatar
Capn Odin
Posts: 1222
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 06:15

Code: [Select all] [Download] GeSHi © Codebox Plus

#Hotstring EndChars-()[]{}:;'"/\,.?!`n `t
::white house::the president in the white house
::white::the white snow
Please excuse my spelling I am dyslexic.
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 06:44

Ah, yeah, you are right, you corrected me for the Space char,
but trying this way, if I write: white in the night
since you can no longer activate the "white house" hotkey I would like to get : "the white snow in the night", but it does not happen.
In summary if I write ... I would like to get
white house in the night -> the president in the white house in the night

white in the night -> the white snow in the night

Is that why I thought of the more generic case where terminal characters do not have influence, using the directive ?* at the start of hotstring.
User avatar
Capn Odin
Posts: 1222
Joined: 23 Feb 2016, 19:45
Location: Denmark

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 08:12

the president in the white house in the night
the white snow in the night

This was written using the above code.

white house + Tab + in the night

white + Tab + in the night
Please excuse my spelling I am dyslexic.
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

25 Sep 2017, 09:08

Now I understand better what you mean, and in fact works perfectly as you say in this specific case and in all cases where you can use terminal characters to define the boundaries of a hotstring.
In fact, it is who writes the terminal character that orders at that time to AHK how to interpret its input.
But let's imagine the case of thousands of hotstring where we want to delegate to the program the use of the hotstring as long as possible: for us it would be impossible because of the huge number of possibilities.
This was the sense of the problem and that is why, to generalize it, I had proposed not to consider the terminal characters, whose use always requires an explicit choice of the writer.
The solution you have set up works perfectly with the use of terminal characters but requires attention and choice by the writer.
What can be done in the general case without terminal characters:

Code: [Select all] [Download] GeSHi © Codebox Plus

#Hotstring ?*
::12345678::len8
::345::len3

I try to write: 0123456789
I obtain 012len36789 but I desire 0len89
How can you give priority to the hotkey as long as possible that is applicable in the specific situation by pausing shorter hotstrings and applying them only in case the longest hotstring is no longer applicable?
For example if I try to write: 012345679 (the 8 is missing)
there would be no way to apply the hotstring "12345678", but only when it reaches "9", then hotstring "345" would be applied, and the end result would be 012len3679
concepter
Posts: 39
Joined: 24 Aug 2017, 13:02

Re: Capture a longer hotstring before a shorter one ?

28 Sep 2017, 05:27

It seems to me that there is no # directive in AHK that implements a hotstring length priority.

That's why I'm thinking of an implementation strategy.
I have a strategy on how to implement it, but I would ask the most experienced experts before starting.
1) Create many hotstring files of the same length, for example hsA .. hsB
2) Create a loop between the hotstring files, starting from the longer hotstring files (hsA) to the shortest hotstring (hsB)
3) Store the imput, whose length is equal to A, in a buffer, so that you can always check for the presence of the best hotstring.

I wonder if this can be done or if there are any limitations and / or advice on how to proceed.
In particular:
1Q) can you have several hotstring files that are activated and deactivated on request?
2Q) Can the main program with the loop use the buffer as an input instead of direct user typing?
3Q) I guess I can simulate the behavior of hotstring but I wonder: can you use the native mechanism in AHK to do all this?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], codude, keitsuke, walfredo, Yahoo [Bot] and 55 guests