Hotstring

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Hotstring

07 Sep 2019, 15:11

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
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Hotstring

07 Sep 2019, 15:52

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)
}
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Hotstring

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
ilhom
Posts: 52
Joined: 19 Aug 2019, 17:58

Re: Hotstring

09 Sep 2019, 14:36

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.
dobbelina
Posts: 39
Joined: 03 Sep 2019, 02:45
Contact:

Re: Hotstring

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
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Hotstring

09 Sep 2019, 16:52

Edit: removed.
Last edited by boiler on 09 Sep 2019, 16:55, edited 1 time in total.
User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Hotstring

09 Sep 2019, 16:54

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.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Hotstring

10 Sep 2019, 06:05

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
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Hotstring

10 Sep 2019, 08:04

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)
}
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Hotstring

11 Sep 2019, 14:15

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 69 times
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Hotstring

12 Sep 2019, 01:48

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.

Last edited by GEV on 11 Dec 2019, 14:23, edited 1 time in total.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Hotstring

14 Sep 2019, 23:40

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 79 times
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Hotstring

15 Sep 2019, 00:21

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.
asad41163
Posts: 268
Joined: 29 Jul 2014, 14:31

Re: Hotstring

24 Sep 2019, 01:21

Many thanks to all my colleagues.
I apologize very much for my late reply.
I will try again if God willing.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Hotstring

24 Sep 2019, 06:24

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).

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mikeyww and 243 guests