Create hotstrings from variables
Posted: 09 Aug 2017, 14:10
Hi,
Is is possible to create hotstrings with the abbreviations and expanded value stored in variables? I need to store hotstrings in an ini file and retrieve/enable them from the ini file. I would need a command similar to the "Hotkey" command as illustrated in the example below. Without such a "Hotstring" command, is there another way to obtain the same result?
This is a working example. It will create an ini file named with with the script's filenname.I've found this solution but it works only for uncompiled scripts. Mine is compiled.
I've also reviewed this solution but it seems quite invasive (it triggers every key of your keyboard).
Thanks.
EDIT (2018-02-11): This is now possible with v1.1.28+. See the Hotstring function and this demo.
Is is possible to create hotstrings with the abbreviations and expanded value stored in variables? I need to store hotstrings in an ini file and retrieve/enable them from the ini file. I would need a command similar to the "Hotkey" command as illustrated in the example below. Without such a "Hotstring" command, is there another way to obtain the same result?
This is a working example. It will create an ini file named with with the script's filenname.
Code: Select all
#NoEnv
#SingleInstance force
#KeyHistory 0
objHotkeyCommands := Object()
StringReplace, strIniFilename, A_ScriptFullPath, .ahk, .ini
IniWrite, !q, %strIniFilename%, Global, Hotkey
IniWrite, DoThis, %strIniFilename%, Global, HotkeyCommand
IniWrite, qq, %strIniFilename%, Global, Hotstring
IniWrite, Some text, %strIniFilename%, Global, HotstringText
; at some other point in the script
IniRead, strHotkey, %strIniFilename%, Global, Hotkey
IniRead, strHotkeyCommand, %strIniFilename%, Global, HotkeyCommand
objHotkeyCommands.Insert(strHotkey, strHotkeyCommand)
IniRead, strHotstring, %strIniFilename%, Global, Hotstring
IniRead, strHotstringText, %strIniFilename%, Global, HotstringText
Hotkey, %strHotkey%, DoHotkey
; I know the "Hotstring" command below does not exit.
; But, if it would, it would do quite the same as the "Hotkey" command.
; Is there a way to obtain the same result?
; Hotstring, %strHotstring%, %strHotstringText%
; Here are a few alternatives that I put here for test
::ww::Some text ; this work
::%strHotstring%::%strHotstringText% ; "qq" does not work at all
return
DoHotkey:
gosub, % objHotkeyCommands[A_ThisHotkey]
return
DoThis:
MsgBox, strHotkey "%A_ThisHotkey%" executed
return
I've also reviewed this solution but it seems quite invasive (it triggers every key of your keyboard).
Thanks.
EDIT (2018-02-11): This is now possible with v1.1.28+. See the Hotstring function and this demo.