I like the idea of Jack Dunning's InstantHotkey but I much prefer hotstrings, which I can remember, to hotkeys, which I often can't.
Thus this script. Feedback appreciated, of course.
Load it several times if you need several instant hotstrings.
Note: If you don't enter a hotstring, but do enter a replacement, it's just going to exit without warning (at least in this incarnation).
Edit April 2, 2018. Doesn't exit if you don't enter a hotstring, shows a message and returns to the GUI when you click OK. Now uses clipboard instead of SendRaw.
Edit April 4, 2018. Does require AHK v1.1.28.00+ to be able to run (thanks, derz00)!
Edit April 13, 2018. Changed 'OldClip = Clipboard' to OldClip = %Clipboard%. Yikes... MAJOR BUG: At present, the hotstrings WILL NOT display '#'. Still looking for a fix 4-13-18 Added :R*: to send hotstring raw.
EDIT: New version April 13, 2018. Now uses clipboard in the proper place, by using NewText := Hotstring(":X*R:"Hstring, "TextAdd").
The label TextAdd now (properly) sends the replacement string via the clipboard. Huge speed increase with large replacement texts.
; InstantHotstring.ahk
; AHK v1.1.28.00+ required!
; by burque505
; Language: English
; Platform: Win7 SP1, 64-bit
; Version 0.0.6 April 13, 2018
; Tested with AHK v1.1.28.02
;
; FREELY ADAPTED FROM InstantHotkey.ahk by Jack Dunning
; (http://www.computoredge.com/AutoHotkey/Free_AutoHotkey_Scripts_and_Apps_for_Learning_and_Generating_Ideas.html#instanthotkey)
;
; InstantHotstring.ahk
; Script Function:
; This little script uses the Hotstrings() function new in AHK 1.1.28+
; Load multiple times for multiple InstantHotstrings.
; Mouse over the tray icon for each instance:
; a tooltip with the hotstring and replacement (or at least a couple of lines of it) will pop up.
;
;
; Changes: SetupString now takes advantage of the :X: parameter. This allows calling a label
global TextInsert ; I'm not sure if this needs to be global
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance off
Gui, Add, Text,, Enter a Hotstring
Gui, Add, Edit, vHString ys
Gui, Add, Edit, w400 r8 vTextInsert xs, <Enter Hotstring Text>
Gui, Add, Button, gSetupString, Set Hotstring
Gui, Show, , Instant Hotstring
Menu, Tray, Add, Show Hotstring GUI, ShowHotstring
Menu, Tray, Add, Add Text, TrayTextAdd
Return
SetupString:
Gui, Submit
If OldHotstring != {
Hotstring(Reset)
If HString !=
{
NewText := Hotstring(":X*R:"Hstring, "TextAdd")
; Line above - ":X*R:" sends raw and allows jumping to a label.
; See https://autohotkey.com/docs/commands/Hotstring.htm
}
Else {
msgbox No hotstring!
gosub, ShowHotstring
}
Menu, Tray, Tip, %HString% %TextInsert%
OldHotstring := HString
Return
TrayTextAdd:
SendInput, !{Escape}
SendRaw, %NewText%
Return
TextAdd: ;This avoids the ho-hum speed of 'Send'
OldClip = %Clipboard%
Clipboard =
Clipboard = %TextInsert%
Clipwait, 0.3 ; Adjust upwards if you are using huge replacements
Send, ^v
Clipboard = %OldClip%
OldClip =
return
ShowHotstring:
Gui,Show
ControlFocus, Edit1
Return
Escape::ExitApp
instant_hotstring.gif (138.64 KiB) Viewed 4295 times
Regards,
burque505
Last edited by burque505 on 13 Apr 2018, 20:45, edited 7 times in total.
This is a nice tool. Any chance you could get it to output to an ahk file so that the set keys can be saved?
P.S. I am very new to AHK. Loving the simplicity.
Draygoes wrote:This is a nice tool. Any chance you could get it to output to an ahk file so that the set keys can be saved?
P.S. I am very new to AHK. Loving the simplicity.
I always thought, the simplicity of :*:ftw::Free the whales (no ending character needed, like in the script above) is already pretty high.
So that is what the script is using? I was thinking that it was exporting as functions because it does not require you to press the space bar to auto replace as ::lol::laugh out loud does.
burque505's script above uses the new Hotstring() function to create a hotstring on the fly, but I think the specific use case for this script is mainly to create temporary hotstrings that I don't want to keep after finishing a specific task. Otherwise, if I wanted to keep a hotstring, I would just use the normal hotstring syntax like shown above and add it directly to a script.
But it would surely be possible to add a hotstring ceated with this script to an ahk-file, for example via FileAppend (this would add it at the end, but that would be fine for a hotstring).
Edited to clarify
Last edited by gregster on 04 Apr 2018, 23:07, edited 1 time in total.
Thanks for your response. The main thing that I wanted to do I have solved, but it probably would not hurt for others using the software if it appends all commands to the end of its own file, or even a new on that can be included at will. Seems like the next logical step to me.
Anyway, I digress. Great work on the program friend!