Page 1 of 1

Hotstring

Posted: 07 Sep 2019, 15:11
by asad41163
Hello my dear colleagues
I work as a data entry, and I always want to assign shortcuts to a large number of words to make it easier to work (say 100 words).
For example, I have this set of words:
English, language, speakers, US, vocabulary, countries, spoken, modern, German, century, dialects, European, official, international, through, grammar
I want to convert it to the following format:
::ish::english
::age::language
::ers::speakers
::ted::united
::ary::vocabulary
and so on...
The abbreviation is the last three letters of each word
So I can put them into a Hotstring.ahk file
thanks in advance

Re: Hotstring

Posted: 07 Sep 2019, 15:52
by GEV
You can use a parsing Loop (or a For Loop in an array) and the Hotstring() function to create the hotstrings dynamically:

Code: Select all

words := "English,language,speakers,vocabulary,countries,spoken,modern,German,century,dialects,European,official,international,through,grammar"
Loop, parse, words, `,
{
	last_three_chars := SubStr(A_Loopfield, -2)
	Hotstring("::" last_three_chars, A_Loopfield, On)
}

Re: Hotstring

Posted: 09 Sep 2019, 13:36
by asad41163
Hello Mr GEV
Thank you so much for your quick response, and I apologize for the delay ..
I have read the topic in the link and did not understand the intended ..
How do I use this code?
Just one example please

Re: Hotstring

Posted: 09 Sep 2019, 14:36
by ilhom
asad41163 wrote:
09 Sep 2019, 13:36
Hello Mr GEV
Thank you so much for your quick response, and I apologize for the delay ..
I have read the topic in the link and did not understand the intended ..
How do I use this code?
Just one example please
You can copy paste his code into a AHK file and run it. You can then type the last 3 characters of any of the words in the list, press enter, then the full word will appear. You can add more words to the list he created.

Re: Hotstring

Posted: 09 Sep 2019, 14:54
by dobbelina
Your code works fine, just put a return in the end.

Code: Select all

::ish::english
::age::language
::ers::speakers
::ted::united
::ary::vocabulary
Return

Re: Hotstring

Posted: 09 Sep 2019, 16:52
by boiler
Edit: removed.

Re: Hotstring

Posted: 09 Sep 2019, 16:54
by boiler
dobbelina wrote:
09 Sep 2019, 14:54
Your code works fine, just put a return in the end.

Code: Select all

::ish::english
::age::language
::ers::speakers
::ted::united
::ary::vocabulary
Return
He knows that the code works. He was asking for a way to easily create a large list, which @GEV showed him.

Also, putting a return at the end of a list of hotstring definitions does not serve a purpose.

Re: Hotstring

Posted: 10 Sep 2019, 06:05
by asad41163
Hello colleagues
thanks for all
Actually I'm asking for an easy way to create a big list .., which @GEV showed me.
I want to simplify more please
Thank you everyone

Re: Hotstring

Posted: 10 Sep 2019, 08:04
by Odlanir
The best method I can think of is to create a file with all the words separated by newline.
You only have to be sure that the last three chars are unique.
Then you can read the file and parse it's content with the GEV script, something like this:

Code: Select all

FileRead, Allfile, the_name_of_your_file
Loop, Parse, Allfile, `n, `r
{
	last_three_chars := SubStr(A_Loopfield, -2)
	Hotstring("::" last_three_chars, A_Loopfield, On)
}

Re: Hotstring

Posted: 11 Sep 2019, 14:15
by asad41163
Many thanks to all colleagues
Odlanir worte: The best method I can think of is to create a file with all the words separated by newline.
You only have to be sure that the last three chars are unique.
Then you can read the file and parse it's content with the GEV script, something like this:
I put the words in a separate file, and tried the code this way, but it did not work, and do not know where the error.

Code: Select all

F4::
FileRead, Allfile, the_name_of_your_file
Loop, Parse, Allfile, `n, `r
{
	last_three_chars := SubStr(A_Loopfield, -2)
	Hotstring("::" last_three_chars, A_Loopfield, On)
}
return
the_name_of_your_file.txt
(47 Bytes) Downloaded 42 times

Re: Hotstring

Posted: 12 Sep 2019, 01:48
by GEV
It doesn't make sense to create the hotstrings in a hotkey definition. Hotkeys terminate the automatic execution of code lines and
the hotstrings created within a hotkey don't remain in the script's memory because the script returns (terminates the current thread and goes back) to the place you were called it from, the auto-execute section, forgetting the settings created in the hotkey, after executing the hotkey's subroutine.


Try it this way:

Code: Select all

#NoEnv
; ...

FileRead, Allfile, the_name_of_your_file.txt
Loop, Parse, Allfile, `n, `r
{
	last_three_chars := SubStr(A_Loopfield, -2)
	Hotstring("::" last_three_chars, A_Loopfield, On)
}

; ...

        RETURN   ; === end of auto-execute section ===

; After the first RETURN you can add more stuff (hotkeys, hotstrings, functions, directives, labels etc.) to the script.


Re: Hotstring

Posted: 14 Sep 2019, 23:40
by asad41163
Sorry, the code is not working
The same problem

Code: Select all

#NoEnv
; ...

FileRead, Allfile, the_name_of_your_file
Loop, Parse, Allfile, `n, `r
{
	last_three_chars := SubStr(A_Loopfield, -2)
	Hotstring("::" last_three_chars, A_Loopfield, On)
}
return
F4::
the_name_of_your_file.txt
(47 Bytes) Downloaded 42 times

Re: Hotstring

Posted: 15 Sep 2019, 00:21
by GEV
You have to use the file's name + extension in

Code: Select all

FileRead, Allfile, the_name_of_your_file.txt
if the file is in the script's working directory

or the full path of the file if it's in another directory.

Re: Hotstring

Posted: 15 Sep 2019, 01:06
by AHKStudent
Make sure you are using AHK 1.1.28+ https://www.autohotkey.com/docs/commands/Hotstring.htm

Re: Hotstring

Posted: 24 Sep 2019, 01:21
by asad41163
Many thanks to all my colleagues.
I apologize very much for my late reply.
I will try again if God willing.

Re: Hotstring

Posted: 24 Sep 2019, 06:24
by lexikos
GEV wrote:
12 Sep 2019, 01:48
It doesn't make sense to create the hotstrings in a hotkey definition.
Unless you want the hotstrings created only after pressing the hotkey (F4), which is apparently not the case here.
... the hotstrings created within a hotkey don't remain in the script's memory because the script returns (terminates the current thread and goes back) to the place you were called it from, the auto-execute section, forgetting the settings created in the hotkey, after executing the hotkey's subroutine.
Hotstrings created by the Hotstring function "remain in the script's memory" until the entire script is exited. In this case perhaps they were not created at all (no one pressed F4).

Exiting a thread only "forgets" the values of thread-specific built-in variables such as A_KeyDelay, and the values of local variables which are freed as an indirect result of exiting the thread. One does not create these settings; one merely changes them.

When the hotkey thread exits, the previous thread resumes. However, in this case there would be no thread to resume, because the auto-execute section would have exited immediately upon reaching the first hotkey, just as if there was a return above it (which is exactly what ListLines would show).