How to turn of a subroutine? Topic is solved

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

How to turn of a subroutine?

13 Mar 2021, 14:29

I tried to place LCtrl:: Return in a code block and got error, ==> Hotkeys/hotstrings are not allowed inside functions. So I am trying to work with a subroutine.

I have two blocks of code in my example, its using a library called TapHoldManager. I am trying to get a single tap to disable Lctrl
in the example below, tap disables Lctrl, while a hold reenables. But running this code I get error of, ==> Target label does not exist.

Code: Select all

BconG6043DX:= new TapHoldManager( 80, 200)
BconG6043DX.Add("esc", Func("BconG6043DX_esc"))
BconG6043DX_esc(isHold, taps, state)  
       {
           if (taps == 1)
           {
               if (isHold == 0)
               {
                   Gosub, Disable_bcon
               }
               Else
               {
                    if (state)
                    {                 
                       Gosub, Disable_bcon, Off
                    }
               }
           }
       }
Disable_bcon:
LCtrl:: Return
Return
Thank you
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to turn of a subroutine?

13 Mar 2021, 14:38

Gosub should have a single parameter, which is a label.

It appears that your subroutine does not really do anything in particular. Hotkeys are not defined in this manner in a block of running code. I cannot tell your intent, but this is likely a bug in your coding.

Explained: Gosub
Mika_erdo
Posts: 41
Joined: 30 Jul 2020, 17:23

Re: How to turn of a subroutine?

13 Mar 2021, 14:48

mikeyww wrote: Gosub should have a single parameter, which is a label.

It appears that your subroutine does not really do anything in particular. Hotkeys are not defined in this manner in a block of running code. I cannot tell your intent, but this is likely a bug in your coding.

Explained: Gosub
Well to simplify it with native AHK code, what I am trying to do would look like this;

Code: Select all

1::
Gosub, Disable_bcon
Return
2::
Gosub, Disable_bcon, Off
Return


Disable_bcon:
LCtrl::Return
Return
I have read the docs page for gosub, its how I was able to construct these examples, butt allot of it goes over my head sadly, like the parameter thing you pointed out.

I am rereading doc page now. Hopefully you can understand my end goal now though.
User avatar
mikeyww
Posts: 27214
Joined: 09 Sep 2014, 18:38

Re: How to turn of a subroutine?  Topic is solved

13 Mar 2021, 14:51

Code: Select all

1::
disable := True
SoundBeep, 1000, 30
Return
2::
disable := False
SoundBeep, 1500, 30
Return

#If disable
LCtrl::Return
#If
Mika_erdo
Posts: 41
Joined: 30 Jul 2020, 17:23

Re: How to turn of a subroutine?

13 Mar 2021, 15:00

Hey that actually works!
it uses a different approach which always great to see, thank you.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], KilliK, mikeyww and 116 guests