Help with triggering hotstrings with unicode please?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Mika_erdo
Posts: 41
Joined: 30 Jul 2020, 17:23

Help with triggering hotstrings with unicode please?

07 Apr 2021, 03:45

So I have this small keypad that has numpad keys, through evilC TapHold Library I use it as a typing keyboard.
So something like this,
1 Tap

Code: Select all

SendInput, {U+0061} ;Charecter a
2 Taps

Code: Select all

SendInput, {U+0062} ;Charecter b
I spent a week thinking it through and getting it just right. I have been very happy with it.
I am now having an issue triggering hotstrings with this keypad.


This example uses vanilla AHK code, pressing 5 and 6 should trigger the hostring but it doesn't work

Code: Select all

5::
SendInput, {U+0061} ;Charecter a
Return
6::
SendInput, {U+0062} ;Charecter b
Return

::ab::myhotstring
Return
Any ideas How I can over come this issue?
Thanks for help.
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Help with triggering hotstrings with unicode please?

07 Apr 2021, 05:18

From the Hotstrings "Remarks" section of the documentation:
By default, hotstrings are never triggered by keystrokes produced by any AutoHotkey script. This avoids the possibility of an infinite loop where hotstrings trigger each other over and over. In [v1.1.06] and later, this behaviour can be controlled with #InputLevel and SendLevel. However, auto-replace hotstrings always use send level 0 and therefore never trigger hook hotkeys or hotstrings.
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: Help with triggering hotstrings with unicode please?

07 Apr 2021, 05:54

Here is an idea.

Code: Select all

5::a
6::
Send b
last := A_PriorKey
Input, next, VL1
If !(next ~= "[()[\]{}':;""/\\,.?!\n \t]") || last != "5"
 Return
Send {BS 3}
::ab::
next := next = "" ? A_EndChar : next
SendInput myhotstring%next%
next =
Return
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Help with triggering hotstrings with unicode please?

07 Apr 2021, 06:54

Or just add #InputLevel 1 for the hotkeys. Perhaps that wasn't clear from my previous post.

Code: Select all

#InputLevel 1
5::
SendInput, {U+0061} ;Charecter a
Return
6::
SendInput, {U+0062} ;Charecter b
Return

::ab::myhotstring
Return

FYI, this code can be shortened to:

Code: Select all

#InputLevel 1
5::SendInput, {U+0061} ;Charecter a
6::SendInput, {U+0062} ;Charecter b

::ab::myhotstring
...because single line hotkeys have an implied return and a return after the hotstring doesn’t serve a purpose. It’s not needed for the hotstring itself and it’s not marking the end of a block of code (hotkeys and hotstrings aren’t part of the auto-execute section).
Mika_erdo
Posts: 41
Joined: 30 Jul 2020, 17:23

Re: Help with triggering hotstrings with unicode please?

07 Apr 2021, 13:02

boiler wrote: Or just add #InputLevel 1 for the hotkeys. Perhaps that wasn't clear from my previous post.

Code: Select all

#InputLevel 1
5::
SendInput, {U+0061} ;Charecter a
Return
6::
SendInput, {U+0062} ;Charecter b
Return

::ab::myhotstring
Return

FYI, this code can be shortened to:

Code: Select all

#InputLevel 1
5::SendInput, {U+0061} ;Charecter a
6::SendInput, {U+0062} ;Charecter b

::ab::myhotstring
...because single line hotkeys have an implied return and a return after the hotstring doesn’t serve a purpose. It’s not needed for the hotstring itself and it’s not marking the end of a block of code (hotkeys and hotstrings aren’t part of the auto-execute section).
Hey thanks for explanation about my misuse of the return command, much appreciated.
As for you solution, I have tried it with vanilla AHK code and it works perfectly!

I've tying to integrate the solution into TapHold manager code brackets, sadly its not working as expected.
In the example bellow, a tap will type a and a hold will type b but the hotstring does not trigger at all.
Do you think it could be a case of the #InputLevel, 1 command being out of scope for the code brackets? as in not local?

Code: Select all

#InputLevel, 1
UBK_Typer:= new TapHoldManager( 0, 170, 1, "") ;( 0, 220, 1, "")
UBK_Typer.Add("2", Func("UBK_Typer_2"))

    UBK_Typer_2(isHold, taps, state)
            {
                if (taps == 1)
                {
                    if (isHold == 0)
                    {
                        SendInput, {U+0061}  ;Letter A
                    }
                    else
                    {
                      if (state)
                                    {
                                        SendInput, {U+0062} ;Letter B
                                    }
                    }
                }
            }

::ab::myhotstring
User avatar
boiler
Posts: 17242
Joined: 21 Dec 2014, 02:44

Re: Help with triggering hotstrings with unicode please?

07 Apr 2021, 13:13

I don't know the inner workings of TapHoldManager, and I don't have it installed, so I can't test this, but you might try adding the line SendLevel, 1 in addition to or instead of #InputLevel, 1.

Reference: SendLevel

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AlFlo, VaritySpice and 117 guests