Create and Test Hotstrings On-the-Fly—then, Save Them for Later Use
When the new Hotstring() function was added to AutoHotkey, I decided to explore its features and capabilities. Over the course of a couple of months, I developed the InstantHotstring.ahk script documenting it along the way in my blog: Jack's AutoHotkey Blog. You can find the source code at my Free AutoHotkey Scripts Page.
The InstantHotstring.ahk script quickly sets up and tests temporary Hotstring combinations for adding repeated and/or long lines of replacement text to any current Windows document or Web editing field. This comes in handy for those situations where you know what text, particular terms, or set of terms you will use repeatedly in a single session.
The GUI window includes a GUI Edit control Hotstring Test Pad for checking the behavior of any newly set Hotstrings. When creating new instant Hotstrings, you can check out various options using the Hotstring Test Pad.
The Test Pad in the image shows the results of the Hotstring "GUI" which immediately appends " (Graphical User Interface)" inserting a preceding space without backspacing to delete the activating Hotstring.
Save Groups of Hotstrings
You can save the Hotstrings to an AutoHotkey *.ahk file of your choice in the [working directory/]Hotstring/folder. You can reload the saved Hotstrings from the any saved .ahk file. When saving the temporarily Hotstrings, you can choose to create a new file by adding a new filename, opt to overwrite an existing file, or, by selecting but not overwriting an existing filename, append more Hotstrings to that same file.
The InstantHotstring.ahk script displays newly created Hotstrings in the DropDownList GUI control. When setting a Hotstring, AutoHotkey immediately activates it and adds it to the DropDownList. You can deactivate/activate Hotstrings using the Toggle Hotstring On/Off button.
The Save Hotstrings button stores all currently active Hotstrings to a filename of your choice. The Load Hotstrings button restores and activates Hotstring code stored in that same (or another) file. (The Load function updates rather than duplicates any Hotstrings with the same activation characters.) The Start Clean button reloads the script wiping out all of the Hotstrings currently running in InstantHotstring.ahk.
The original LoadHotstrings subroutine ran slow for a number of reasons (for discussion in my AutoHotkey blog). I've rewritten it for speed but include the former script (InstantHotstring(SlowLoad).ahk) for review by those reading earlier blogs.
The GUI window for setting up the Hotstrings opens immediately when the script loads. After closing the Hotstring window, you can reopen it by right-clicking on the icon in the System Tray and selecting Show Instant Hotstrings.
November 13, 2019: The version of the script available at the Free AutoHotkey Scripts page now loads a default Hotstring file from a path and filename saved in the Windows Registry. Use "Save Hotstrings" button to set default file.
This script uses tips and tricks found in my AutoHotkey books and AutoHotkey blogs. To find my numerous blogs about the development of this script (in reverse order), search my blog using "InstantHotstring" in the primary search window.
Instantly Create and Save Hotstrings with the Hotstring() Function
- jackdunning
- Posts: 126
- Joined: 01 Aug 2016, 18:17
- Contact:
Instantly Create and Save Hotstrings with the Hotstring() Function
Last edited by jackdunning on 25 Nov 2020, 08:13, edited 2 times in total.
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
Thanks, Jack. I created a very simplistic script along the same lines some time ago, see this thread.
Yours has all the bells and whistles.
Yours has all the bells and whistles.
- jackdunning
- Posts: 126
- Joined: 01 Aug 2016, 18:17
- Contact:
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
The latest version of the InstantHotstrings.ahk script (download link) now loads the default Hotstring file by accessing the file path and name saved in the Windows Registry. To set the default, click the "Save Hotstrings" button for adding the loaded Hotstrings to a file, then, when prompted, opt to set the file as default.
Jack Dunning
I have a passion for helping new users grow maniacal about AutoHotkey Windows scripting.
Jack's AutoHotkey Blog
Free AutoHotkey Scripts and Apps for Learning Script Writing and Generating Ideas
AutoHotkey Books
AutoHotkey Library Bundles
Jack's Motley Assortment of AutoHotkey Tips
I have a passion for helping new users grow maniacal about AutoHotkey Windows scripting.
Jack's AutoHotkey Blog
Free AutoHotkey Scripts and Apps for Learning Script Writing and Generating Ideas
AutoHotkey Books
AutoHotkey Library Bundles
Jack's Motley Assortment of AutoHotkey Tips
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
mslonik's related hotstring topic was split from this topic, and now can be found here: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=82352
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
Hi Jack,
I'm not sure if you're still tracking this thread, but would it be possible for you to post the zip of this (Instant Hotstring) project? The zip you have linked here
https://computoredgesoftwareshowcase.com/2019/04/02/instanthotstring-ahk-autohotkey-scripts/
is "File not found."
EDIT: I contacted Jack, and he has updated the link.
I'm not sure if you're still tracking this thread, but would it be possible for you to post the zip of this (Instant Hotstring) project? The zip you have linked here
https://computoredgesoftwareshowcase.com/2019/04/02/instanthotstring-ahk-autohotkey-scripts/
is "File not found."
EDIT: I contacted Jack, and he has updated the link.
ste(phen|ve) kunkel
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
Sorry to necro this thread.
But I'm kinda losing my mind on something I seem unable to accomplish.
I want this script to support multiple lines per HotString.
I changed the GUI Input field to allow multiple lines
And in the sandbox it works spitting out all the lines I set.
When saving the file&Hotstrings all the lines are saved - just when loading the saved HotStrings it deletes all extra lines.
Is there a way I can change the script to make this happen? I feel like that just the "loading" part needs to be reworked to tell the script that multiple lines are fine & loaded.
If anybody has an idea how to accomplish this, please please for the love of everything help me. I wasted a lot of hours trying to get it to work on my own.
This is the "LoadingHotStrings" - Function:
But I'm kinda losing my mind on something I seem unable to accomplish.
I want this script to support multiple lines per HotString.
I changed the GUI Input field to allow multiple lines
Code: Select all
Gui, Hotstring:Add, Edit, w400 h100 vTextInsert xs, <Enter Hotkey Text>
When saving the file&Hotstrings all the lines are saved - just when loading the saved HotStrings it deletes all extra lines.
Is there a way I can change the script to make this happen? I feel like that just the "loading" part needs to be reworked to tell the script that multiple lines are fine & loaded.
If anybody has an idea how to accomplish this, please please for the love of everything help me. I wasted a lot of hours trying to get it to work on my own.
This is the "LoadingHotStrings" - Function:
Code: Select all
LoadHotstrings:
Gui, Hotstring:+OwnDialogs
If (InStr(FileExist("\Hotstrings"), "D") = 0)
FileCreateDir, Hotstrings
FileSelectFile, OpenFile , , %A_ScriptDir%\Hotstrings\, , *.ahk
If ErrorLevel
Return
; Use *P65001 to read UTF-8 file *P1200 for UTF-16
FileRead, AddHotstring, *P65001 %OpenFile%
StrReplace(AddHotstring, "`n" , "`n", OutputVarCount)
HotstringCount := 0
DupCount := 0
UpdateCount := 0
StartTime := A_TickCount
GuiControl, Disable, Button12
Progress, R0-%OutputVarCount% x640 y540,%OutputVarCount% lines in file,Loading Hotstrings • • • ,%OpenFile%
ControlGet, DropDown, List, , ComboBox1, A
If (DropDown != "")
DropDown := DropDown . "`n"
Loop, Parse, AddHotstring, `n
{
If (A_Loopfield ~= "^:.*?:.+?::[^\s]") ; Check for valid Hotstring
{
Hotstring := StrSplit(A_LoopField, ":", ,5)
HotText := StrSplit(A_LoopField, A_Space . ";") ; Removes comments on same line
If (InStr(DropDown, RTrim(HotText[1]," `r")))
{
DupCount++
Continue
}
UpdateCheck := ":" . Hotstring[3] . "::"
If (InStr(DropDown, UpdateCheck))
{
RegExMatch(DropDown, ":[\w?*]*:" . Hotstring[3] . "::.*?(`r|`n)", HotstringMatch)
; MsgBox % HotstringMatch
; MsgBox % HotText[1]
DropDown := StrReplace(DropDown, HotstringMatch , RTrim(HotText[1]," `r") . "`n")
; msgbox %DropDown%
UpdateCount++
}
Else
{
DropDown := DropDown . RTrim(HotText[1]," `r") . "`n"
}
HotText := StrSplit(HotString[5], A_Space . ";") ; Removes comments on same line
Hotstring(":" . HotString[2] . ":" . HotString[3], RTrim(HotText[1]," `r") , "On")
HotstringCount++
}
Progress, %A_Index% ,%A_Index% of %OutputVarCount% lines in file
}
Progress, Off
NewList := "|" . StrReplace(Dropdown,"`n","|")
GuiControl,, ComboBox1 , %NewList%
GuiControl, Enable, Button12
GuiControl, Hotstring:Choose, ComboBox1, 1
GoSub ViewString
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
Hi @teolala,
Welcome to this forum! Actually you're right, you shouldn't ask this kind of questions in this thread as there is little chance somebody even read it. By surprise I saw it today.
I think I know what could be wrong. Try this:
Advice from my side: try to isolate your issue, I mean smaller chunk of code which is cumbersome. Also give a try to OutputDebug command with your code. Finally give a try to successor, the Hotstring viewtopic.php?f=6&t=82352 application.
Good luck, mslonik
Welcome to this forum! Actually you're right, you shouldn't ask this kind of questions in this thread as there is little chance somebody even read it. By surprise I saw it today.
I think I know what could be wrong. Try this:
Code: Select all
StrReplace(AddHotstring, "``n" , "`n", OutputVarCount)
Good luck, mslonik
My scripts on this forum: Hotstrings Diacritic O T A G L E
Please become my patreon: Patreon
Written in AutoHotkey text replacement tool: Hotstrings.technology
Courses on AutoHotkey
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
Thank you @mslonik
Great input, but it did not solve the problem. Really appreciate it, though.
I just posted a thread in the "Help" forums.
I want the script to only recocnize a new HotString, once it finds a new line AND a ":" at the beginning of a line.
Thread needs to be approved first, otherwise it would link it here.
Great input, but it did not solve the problem. Really appreciate it, though.
I just posted a thread in the "Help" forums.
I want the script to only recocnize a new HotString, once it finds a new line AND a ":" at the beginning of a line.
Thread needs to be approved first, otherwise it would link it here.
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
@teolala,
By looking at your code, I think that you are already more advanced than me, so I am hesitant to offer suggestions. Anyway... Some thoughts for hotstring replacements:
Maybe if you can get the hotstring replacement from your edit box, to this format by using StrReplace or RegExReplace or something??
By looking at your code, I think that you are already more advanced than me, so I am hesitant to offer suggestions. Anyway... Some thoughts for hotstring replacements:
Code: Select all
::sig::
(
This is my multi-
line signature:
_____________
SteveK
)
::sig2::This also`nworks`n`n_________`nSteveK
ste(phen|ve) kunkel
Re: Instantly Create and Save Hotstrings with the Hotstring() Function
hey @kunkel321
thank you for the input, much appreciated.
I created a separate topic for my problem.
viewtopic.php?p=510375#p510375
thank you for the input, much appreciated.
I created a separate topic for my problem.
viewtopic.php?p=510375#p510375
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 239 guests