Hi again Steve, thanks for helping out! I've been testing your code (along with my older THM functions) for the past few days and I've got a few things to say.
1.
SteveMylo wrote: ↑28 Jan 2023, 16:44
@Epoch Hi Epoch.
This code works while Holding the "F3" key on my laptop as I don't have F13... and "H" key will perform a SoundBeep.
I believe this is what you want, although I don't have a F13 button and since you are mapping it, you may need the other THM function that maps keys. I'm not sure.
I've tried your code and of course it's working and yes that's pretty much what I am after, except I want it for F13 & Space and I also want double tap and hold actions (maybe triple tap too). Whereas your script works perfectly though, when I adapt it on my needs
it's "only" kinda working, meaning it's a bit inconsistent.
Code: Select all
#Include <TapHoldManager>
thm := new TapHoldManager()
thm.Add("F13", Func("F13_Func"),,,1) ; increase "1" to suit if you are tapping more than once
thm.Add("Space", Func("Space"),350,500,3)
thm.PauseHotkey("Space")
F13_Func(isHold, taps, state){
global thm
if (isHold=1) & (taps=1) & (state=1){ ; allows "Space" to work while holding down because (state=1)
thm.ResumeHotkey("Space")
return
}
if (isHold=1) & (taps=1) & (state=0){ ; Pauses "Space" when F13_Func is released because (state=0)
thm.PauseHotkey("Space")
return
}
}
Space(isHold, taps, state){
global thm
if (isHold=0) & (taps=1) & (state)
{
ToolTip One Tap!
Sleep 500
ToolTip
Return
}
if (isHold=0) & (taps=2) & (state)
{
ToolTip Two Taps!
Sleep 500
ToolTip
Return
}
if (isHold=0) & (taps=3) & (state)
{
ToolTip Three Taps!
Sleep 500
ToolTip
Return
}
if (isHold=1) & (taps=1) & (state)
{
ToolTip One Hold!
Sleep 500
ToolTip
Return
}
}
return
~Esc::ExitApp
The problem is that while it's working properly 75% of the time, sometimes it's missing taps, I'll tap three times and the tooltip will report only two etc. Also, when trying the "hold" action I'll receive a message saying:
"71 hotkeys have been received in the last X seconds" asking me if I want to terminate the script and Space stops working. Searching in the forum, I've found out this usually means a hotkey sending itself causing a loop and suggested solutions are to add
"$" before the hotkey (didn't work) or
#MaxHotkeysPerInterval 500 on the top of the script (it seems to get rid of the warning popup but not of the missing taps inconsistency). But it sounds like the proper way to deal with this is fixing a (possible) mistake on the code itself...
Either I am adapting something wrong or the F13 is the culprit. Btw, I am using the Logitech G600 mouse which has a third mouse button on the right of the classic right button which acts like a shift button to have twice as many actions (I think it's still the only one in the market having that, so useful!). Now, this is a Logitech proprietary thing and it's not seen by AHK on its own. Using Logitech software though with a Lua script, I can set it to act as "F13" and AHK sees it. Here is the Lua script btw, I found it online, didn't come up with it myself:
Code: Select all
function OnEvent(event, arg, family)
if event == "MOUSE_BUTTON_PRESSED" and arg == 6 then -- Change 3 to whatever Gkey you want to use.
PressKey("F13"); else
ReleaseKey("F13");
end
end
I've been using F13 combined with several other other keys for a while and never had a problem, probably there's something wrong in my adaptation?
2). Judging from your answer to
@Bachelar in the post right above mine, it seems like having a dedicated script for tabholdmanager on its own is necessary, right? I mostly work with one large, megascript doing stuff in several programs, but as I’ve said it seems it doesn'to play well with Timers, seeing they both need to be on the top.
3). With that in mind, I put together a new Tabholdmanager script but when trying to combine this new hotkey with my older THM functions, several issues seem to appear. Messages that say something along the lines
“functions can’t contain other functions” or some functions seemingly breaking others.
Rather than troubling you with posting everything, I’ll try to put things in the right place myself for a little longer so I gotta ask… the order things are layered seems very important, right? As a reminder, except the
thm.Add and the
(isHold, taps, state) parts, I also use the context sensitive lines EvilC told me about (you've also posted an alternative way yourself, I'll try this one too, but I am not sure if you can have multiple lines initiating THM, one for each program) the other day, in order to limit the programs the hotkeys have an effect on. I've got these for example:
Code: Select all
Hotkey, IfWinActive, ahk_exe AutoHotkeyU32.exe
Hotkey, IfWinActive, ahk_exe waterfox.exe
I think am doing something wrong in the order I put things, I've tried putting
in order to stop context-sensitivity, but I am not sure whether this line is correct or if that's the only problem.
Also, can I group the
thm.Add parts together with their
(isHold, taps, state) counterparts or
should I place all the thm.Add parts together first and THEN the functions? The former looks more tidy but I get the feeling it causes some of the issues mentioned. Or perhaps it has to do with some
Gosub / Goto commands I've got in my older THM hotkeys. As I've said, up until now I was using THM on top of my megascript and I've found that necessary to get around the
"functions can’t contain other functions” message I was also getting in cases like having a THM hotkey execute something that includes a function combined with Findtext stuff, or simply to reference some other code snippet found later in the script and not have to repeat it.
...Or maybe, again, it's my adaption of your new code that causes a mess...
4.
I'm utilizing the thm.PauseHotkey("h") & thm.ResumeHotkey("h") functions in THM.
BTW This function is the Perfect Keywait, and I no longer use Keywait anymore, I just copy and paste THM's function. Keywait often has issues.
That's quite interesting, I'd like to know more about this. To be honest, as with a lot advanced AHK stuff, I don't fully understand the way THM works. Studying this thread I've ended up with a working "template" to perform tap, double tap, triple tap and hold actions and I adapt it each time changing actions and hotkeys.
But I can't say I fully comprehend what happens under the hood, why for example you need to put taps=1, when it's not a tap but a hold (otherwise it won't work) on:
Code: Select all
if (isHold=1) & (taps=1) & (state)
and what exactly you do with "states". I mean understand you use it to allow space ("h" in your example) working normally when I don't use the combination, but not how this line/states working.