1
votes

In my main Autohotkey script I have several hundred hotstrings like these:

::fe::for example
::f::and
::fi::for instance
::fo::fortunate
::foy::fortunately
::glo::global
::gloy::globally
::ha::have
::hv::however

Fairly often it would be convenient to trigger a hotstring manually (e.g. by pressing ALT-9) rather than pressing and end character. Is there a way to do this? I haven't found anything in my Googling, so maybe there isn't. But it would be useful.

I've read the hotstrings options e.g. :*: but this isn't the same - I want normal hotstring operation, but also the option to manually force them to trigger as needed.

3

3 Answers

2
votes

Updated: So what you are in fact looking for is using ALT+9 as an end character. I'm not sure but you can probably not use key-combinations for that (see hotstring doc). I cannot think of a really clever way of doing that right now. You might try something like

::fe::
    Transform, CtrlC, Chr, 3 ; comes from ahk input documentation, I never really understood how this is supposed to work but I guess there is a code for alt 9 as well somehow
    input, key, L1 I M ; wait for the next 1 key
    if(key==CtrlC)
        sendraw forExample
return

Old answer:

You have to outsource the hotstring body:

::fe::gosub forExample

forExample:
    send for example
return

, then you can define a hotkey somewhere:

!9::gosub forExample

If you want to be cool, use functions instead of subroutines.

Note:

::fe::something

is just a short form for

::fe::
     send something
return
2
votes
::fe::for example
::f::and
::fi::for instance
::fo::fortunate
::foy::fortunately
::glo::global
::gloy::globally
::ha::have
::hv::however

!8:: trigger_hotstring("fi")
!9:: trigger_hotstring("ha")

trigger_hotstring(hotstring){
Loop, Read, %A_ScriptFullPath%  
{
    If InStr(A_LoopReadLine, "::"hotstring "::")
    {
         SendInput, % StrSplit(A_LoopReadLine,"::"hotstring "::").2
                break
    }
}
}
1
votes

If you use AutoHotkey v1.1.06+ you can use #InputLevel

::fe::for example
::f::and
; and so on

#InputLevel, 1 ; sending space will trigger hotstrings above this line
!F9::Send {space}

Edit:

I now see you want to omit the end char which needs a bit of extra work

One way would be to duplicate the hotstrings with additional options:

::fe::for example
:*O:fe_::for example ; duplicate the hotstrings like so
::f::and
::fi::for instance
::fo::fortunate
; and so on

#InputLevel, 1
!9::Send _

Another way would be to remove the endchar

::fe::for example
::f::and
::fi::for instance
::fo::fortunate
; and so on

#InputLevel, 1
!9::
Send {space}
Sleep 100 ; give it time to expand the hotstring, experiment with timing
Send {bs} ; now remove trailing space
Return