Trigger a subroutine with a single-line HotSTRING

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WeThotUWasAToad
Posts: 312
Joined: 19 Nov 2013, 08:44

Trigger a subroutine with a single-line HotSTRING

Post by WeThotUWasAToad » 22 Dec 2017, 22:09

Hello,

Is there a way to trigger a subroutine with a single-line HotSTRING?

Designating a HotKEY to run a subroutine can be done in a single line:

Code: Select all

F1::GoSub, SomeSubRoutine
However, at least three lines are required (as far as I know) for a HotSTRING to run the same subroutine:

Code: Select all

:*:htstrng::
GoSub, SomeSubRoutine
Return
...since using a HotSTRING in a single-line (as with the HotKEY), will simply return whatever text resides in the line:

Code: Select all

:*:htstrng::GoSub, SomeSubRoutine	; returns "GoSub, SomeSubRoutine"
Is there some HotSTRING configuration or trick to enable single-line HotSTRING-triggered subroutines?

Thanks
A ------------------------------ [A LOT OF SPACE] ------------------------------ LOT

"ALOT" is not a word. It never has been a word and it never will be a word.
"A LOT" is 2 words. Remember it as though there's [A LOT OF SPACE] between them.

User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
Contact:

Re: Trigger a subroutine with a single-line HotSTRING

Post by KuroiLight » 22 Dec 2017, 23:56

Don't think this is possible according to Hotstrings: "Note that the commands must appear beneath the hotstring".
This is likely due to the way hotstrings are evaluated by the parser. (?)
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Trigger a subroutine with a single-line HotSTRING

Post by Helgef » 23 Dec 2017, 05:50

However, at least three lines are required (as far as I know) for a HotSTRING to run the same subroutine:
If it is any comfort, you can use goto and skip the return.

Happy hollidays :xmas:

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Trigger a subroutine with a single-line HotSTRING

Post by jeeswg » 23 Dec 2017, 06:55

A workaround would be to have an array, you look up the hotstring (use A_ThisHotkey) in the array, and then invoke a function, or function with a particular parameter, accordingly. All the hotstrings would point to the same subroutine.

Code: Select all

oArray := {abc:1,def:2,ghi:3}
:*:abc-::
:*:def-::
:*:ghi-::
MsgBox, % A_ThisHotkey "`r`n" SubStr(A_ThisHotkey, 4, -1)
vNum := oArray[SubStr(A_ThisHotkey, 4, -1)]
MsgBox, % vNum
;Func%vNum%()
;Func(vNum)
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Post Reply

Return to “Ask for Help (v1)”