Hotstring

Get help with using AutoHotkey and its commands and hotkeys
asad41163
Posts: 250
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: 791
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: 250
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: 44
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: 10
Joined: 03 Sep 2019, 02:45
GitHub: dobbelina

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: 2628
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: 2628
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: 250
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: 473
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: 250
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 6 times
GEV
Posts: 791
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.

asad41163
Posts: 250
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 2 times
GEV
Posts: 791
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.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], blue83, flyingDman, Getfree, ineuw, JoeWinograd, TAC109 and 89 guests