Using Hotkey If, With EvilC TapHoldManager Library Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
gaberiel__2
Posts: 14
Joined: 18 Jan 2023, 14:18

Using Hotkey If, With EvilC TapHoldManager Library

Post by gaberiel__2 » 08 Feb 2023, 07:26

Lately I have been using Autohotkey to help me get past my left hands injury and the pain I get when I "push it" by reaching out for keys, especially, when my other hand is on the mouse


I recently had this brilliant idea that will let me eliminate reaching out for keys, by using a keypad instead of a full sized keyboard.

My idea is to use a VIM style hotkey\\editing (The Linux\\text editing tool) design.

when I tap NumpadSub, then first tap of NumpadMult should perform a special action. After this first tap of NumpadMult future taps should perform the default windows function, as if no AHK scripts were running.

The thing is, to make up for the small number of keys available, I want to use EvilC's TapHoldManager library to achieve this. I have spent the past few days increasing my knowledge of this library.

Using This this question here and this answer by user u\ExpiredDebitCard HERE I came up with this:

Code: Select all

#include <TapHoldManger>
THMLeader:= new TapHoldManager(200,400,2) 
THMLeader.Add("NumpadSub", Func("LeaderKey__NumpadSub")) 
THMLeader.Add("NumPadMult", Func("LeaderKey__NumPadMult"))

LeaderKey__NumpadSub(isHold, taps, state) 
    {
    if (taps == 1)
        if (isHold == 0)
            {
                Tooltip, THMLeader Tap x1
                TestFlag := 1
            }
            else
            {
            if (state)
                            {
                                Tooltip, THMLeader Hold x1     
                                
                            }
                ; else 
                ;           {
                ;           } 
            }
    }
LeaderKey__NumPadMult(isHold, taps, state) 
    {
    if (taps == 1)
        if (isHold == 0)
            {
                Tooltip, LeaderKey__NumPadMult Tap x1
            }
            else
            {
            if (state)
                            {
                                Tooltip, LeaderKey__NumPadMult Hold x1  
                            }
                ; else 
                ;           {
                ;           } 
            }
    }


TestFlag := 1

Hotkey If,TestFlag == 1
;Hotkey If,(TestFlag == 1)
THMSubKey:=New TapHoldManager(200,400,2)   
THMSubKey.Add("NumpadMult", Func("SubKey__NumPadMult"))
#If    

SubKey__NumPadMult(isHold,taps,state)
    {
        if (taps == 1)
            if (isHold == 0)
                {
                    Tooltip, SubKey__NumPadMult Tap x1
                    TestFlag := 0
                }
                else
                {
                if (state)
                                {
                                    Tooltip, SubKey__NumPadMult Hold x1  
                                    TestFlag := 0
                                }
                    ; else 
                    ;           {
                    ;           } 
                }
    }
My intention with the above code is that, SubKey__NumPadMult code block should only ever be active if variable TestFlag is set to 1. Only single tap of NumpadSub can set TestFlag to 1. so

So in short,
  • A single tap of NumpadSub followed by NumpadMult will print SubKey__NumPadMult Tap x1.
  • A single tap of NumpadMult NOT preceded by a tap of NumpadSub will print LeaderKey__NumPadMult Tap x1

I am having issues with getting Hotkey If,TestFlag == 1 to work though. Running the above code gives me a runtime error:

Code: Select all

Error:  Parameter #2 must match an existing #If expression.
Changing it around like. Hotkey If,(TestFlag == 1) has not helped either.

What am I doing wrong here? I have tried many things, nothing seems to be giving in. Any help or ideas would be great.

Thanks for any help

Rohwedder
Posts: 7625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using Hotkey If, With EvilC TapHoldManager Library  Topic is solved

Post by Rohwedder » 09 Feb 2023, 02:38

Hallo,
see manual Hotkey and replace:

Code: Select all

Hotkey If,TestFlag == 1
;Hotkey If,(TestFlag == 1)
THMSubKey:=New TapHoldManager(200,400,2)   
THMSubKey.Add("NumpadMult", Func("SubKey__NumPadMult"))
#If
by:

Code: Select all

Hotkey If,TestFlag == 1
;Hotkey If,(TestFlag == 1)
THMSubKey:=New TapHoldManager(200,400,2)   
THMSubKey.Add("NumpadMult", Func("SubKey__NumPadMult"))
#IF TestFlag == 1 ; <<<< needed!
#If
Untested, I just fixed the displayed error.

Post Reply

Return to “Ask for Help (v1)”