global is needed because functions have their own local variable space. Without
global ahi, the function would not be able to use the
ahi variable that was declared outside the function
state holds the state of the input key - for a tap, it is always -1, but on a hold, it is 1 when you press the key and 0 when you release the key. So this code just ensures that the messagebox only shows on press of space, but not release
; then put the space hotkey in action? Is that it? Correct
; Spacebar hotkey is paused untill the function above (E) is executed Correct
Would it be possible to "delay" the effect of "~", like...
Bear in mind that when you subscribe to a key, the function associated with that key is not called at all until it has decided what you have done - ie it will not call the function after the 1st tap until it has decided that too long has passed, and a 2nd tap is not going to come.
On a double-tap, the function is only called once, after the 2nd tap, it is not called after the 1st tap
It's also worth mentioning that the intended way of specifying a prefix is by using the appropriate parameter, either:
thm := new TapHoldManager(,,, "$~") ; All hotkeys have pass-through
or
thm.Add("´", Func("FuncChromeTabNext"), , , , "$~", "ahk_exe chrome.exe") ; This hotkey has pass-through
Be aware that when you have a subscribed key that sends itself (ie subscribing to ' and the function for ' potentially sending '), you must make sure the $ prefix is in effect, else you will get an infinite loop (you press ', the function sends ', which triggers the ' hotkey, which sends ', which triggers the ' hotkey, etc...)
THM defaults to a prefix of $, but if you override the prefix (eg you wish to add ~), you should also include the $ prefix to stop it self-triggering (ie $~ not ~)
So if you want to sometimes block, and sometimes not block the key, what you have to do is to block the key, and then use logic within your function to decide whether to send the key that was blocked, or take some other action:
Code: Select all
thm.Add("'", Func("FuncChromeTabPrevious"), , , , , "ahk_exe chrome.exe")
FuncChromeTabPrevious(isHold, taps, state)
{
if (isHold)
{
if (taps == 1)
Send ' ; on one tap, just pass through a tap of '
else if (taps == 2)
Send, ^+{Tab} ; on two taps, send previous tab
}
}
This code is a bit overly-simplistic (ie it does not handle a hold of '), but hopefully you get the idea
Another thing worth mentioning is that if you only ever want to support double-taps, and not triple-taps or more, then set the "maxTaps" parameter to 2.
This will speed up response times - when you double-tap, it will not wait to see if a 3rd tap happens before firing the function