0
votes

I am quite new on AutoHotKey, and I'm trying to make my macro system. Currently I have a system that looks like this: I have text variables

hi =
(
Hello, 

Some more text
)

a Hotstring

::\hi::
Macro(hi)
return

And a function Macro:

Macro(text)
{
ClipSaved := ClipboardAll       ; save clipboard
clipboard := text
ClipWait
Sleep, 150
Send, ^v
clipboard := ClipSaved       ; restore original clipboard
return
}

The reason for using a function with clipboard is because long text blocks tend to have a delay until they are printed out, an issue that does not occur with the function.

I've found a concept called dynamic hotstrings, and I think I can somehow implement it so that I wouldn't have to write the second displayed block for every text field, but instead have a one hotstring that would understand that if it's my input starts with \ and there is a variable in the script under the name x that follows it, it should execute Macro(x), but I have never found any similar examples.

Could you provide me with a code sample or give any leads to what I should check out?

1

1 Answers

1
votes

There are several dynamic Hotstring AutoHotkey functions, but this is probably the one you want to use Hotstring by menixator

So you need to download the hotstring.ahk and #include it as in the examples.

#SingleInstance, force
#include Hotstring.ahk

hi=
(
Hello,

Some more text
)

bye=
(
So long,

Some more text
)

Hotstring("/hi", "Paste")
Hotstring("/bye", "Paste")
return

Paste:
text:=Trim($,"/") ; we need to get rid of the leading /
text:=% %text%      ; and need to dereference it
Macro(text) 
Return

Macro(text)
{
ClipSaved := ClipboardAll       ; save clipboard
Clipboard := text
ClipWait
Sleep, 150
Send, ^v
clipboard := ClipSaved       ; restore original clipboard
return
}

There are some more elegant ways to do it, especially with the variables, you could store them in a global object (associative array) for example, but this should get you going.