Re: TapHoldManager - Long Press / Multi Tap / Multi Tap and Hold / Any number of Taps / Multi-Keyboard / Joystick button
Posted: 01 Oct 2020, 07:40
@evilCIt works now. Thank you!
Let's help each other out
https://www.autohotkey.com/boards/
Code: Select all
thm.Add("-", Func("FuncEditUserCommands"))
FuncEditUserCommands(isHold, taps, state)
{
if (taps)
{
if (taps == 1)
Send -
else if (taps == 2)
Send, {Space}-{Space}
else if (taps == 3)
Run, "C:\Program Files\AutoHotkey\SciTE\SciTE.exe" "C:\Users\Avastgard\Desktop\UserCommands.ahk"
}
}
The quoted part of the code you provided (tap followed by hold) worked, but apparently it only works every other time (works once, doesn't work the next time, works the following time and so on). Do you have any idea why this is happening and how to fix it?evilC wrote: ↑27 Jun 2020, 20:11Only support for the same key is built into the library, but no reason you could not implement that functionality yourself by just subscribing to e and space, and only enabling the space subscription once e was tapped twiceCode: Select all
#include Lib\TapHoldManager.ahk thm := new TapHoldManager() thm.add("e", func("eFunc")) thm.add("Space", func("spaceFunc")) thm.PauseHotkey("Space") eFunc(isHold, taps, state){ global thm if (taps == 2 && !isHold){ thm.ResumeHotkey("Space") } } spaceFunc(isHold, taps, state){ global thm if (taps == 1 && isHold && state){ thm.PauseHotkey("Space") Msgbox You tapped e twice then held space } }
@evilC, is there anyway to solve the problem in my script above?Avastgard wrote: ↑03 Jan 2021, 15:17Hi there, and sorry it took me so long to report back, but I only managed to test this now. Your pass-through code worked fine, but I had to change one isHold to taps to get it working. There is only a minor thing about it that hopefully someone could help me fix: since I tell the script to wait a while to send a characater, what is usually happening is that during normal typing, a character handled by TapHoldManager will sometimes be typed after a character when it was supposed to come before it. So, for example, in a script like this:
sometimes typing "e-mail" will result in "em-ail", because I hit "m" before the script could send "-". I know I could simply reduce tapTime, but this in turn makes triple tapping more difficult, as I hould have to press "-" incredibly fast to execute the specified action. So, is there a way to make sure whatever I type after "-" only gets sent after tapTime expires?Code: Select all
thm.Add("-", Func("FuncEditUserCommands")) FuncEditUserCommands(isHold, taps, state) { if (taps) { if (taps == 1) Send - else if (taps == 2) Send, {Space}-{Space} else if (taps == 3) Run, "C:\Program Files\AutoHotkey\SciTE\SciTE.exe" "C:\Users\Avastgard\Desktop\UserCommands.ahk" } }
As for this part of the code:
The quoted part of the code you provided (tap followed by hold) worked, but apparently it only works every other time (works once, doesn't work the next time, works the following time and so on). Do you have any idea why this is happening and how to fix it?evilC wrote: ↑27 Jun 2020, 20:11Only support for the same key is built into the library, but no reason you could not implement that functionality yourself by just subscribing to e and space, and only enabling the space subscription once e was tapped twiceCode: Select all
#include Lib\TapHoldManager.ahk thm := new TapHoldManager() thm.add("e", func("eFunc")) thm.add("Space", func("spaceFunc")) thm.PauseHotkey("Space") eFunc(isHold, taps, state){ global thm if (taps == 2 && !isHold){ thm.ResumeHotkey("Space") } } spaceFunc(isHold, taps, state){ global thm if (taps == 1 && isHold && state){ thm.PauseHotkey("Space") Msgbox You tapped e twice then held space } }
Code: Select all
#NoEnv
SendMode Input
#SingleInstance, Force
#Persistent
vTab:= 2
z::
SendEvent {Tab %vTab%}
Sleep 11
SendEvent {Enter}
Sleep, 111
vTab++
return
Code: Select all
#include C:\Users\Mylo\Documents\AutoHotkey\SCRIPTS_STARTUP\TapHoldManager-master\lib\TapHoldManager.ahk
thm := new TapHoldManager()
thm.Add("x", Func("xtests"))
xtests(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){
vTab:= 2
SendEvent {Tab %vTab%}
Sleep 44
SendEvent {Enter}
Sleep, 111
vTab++
return
}
}
return
I use this loop script below.... so when my mouse turns into an IBeam in a text field, it suspends the script instantly so I can type what I want. Not sure if that helps
Code: Select all
thm := new TapHoldManager()
thm.Add("~x", Func("x_Shortcut"))
;;;;;;;;;;;;;;;;;;; My Loop script
Loop
{
while A_cursor = "IBeam"
{
Sleep, 222
Suspend, on
}
while A_cursor != "IBeam"
{
Sleep, 222
Suspend, off
}
}
;;;;;;;;;;;;;;;;;;; END My Loop script
x_Shortcut(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){
; Your Script
Hi, this tutorial explains the whole set up for 2nd keyboard. It’s a long tutorial & that section doesn’t start till half way through. Sorry if it’s not what your asking.
That is a truly brilliant tutorial video. So concise and simply put. Thank you.Hi, this tutorial explains the whole set up for 2nd keyboard. It’s a long tutorial & that section doesn’t start till half way through. Sorry if it’s not what your asking.
https://youtu.be/gZxebHjsXyw
Code: Select all
ITH1.Add("L", Func("Func1"))
Func1 (isHold, taps, state)
{
if (taps=1)
{
Send,{1}
Send, {tab 5}
Send, {O}
Sleep, 300
Send, {tab 3}
Sleep, 300
Send,{2000}
Send,{tab}
}
if (taps=2)
{
Send,{1}
Send, {tab 5}
Send, {C}
Sleep, 300
Send, {tab}
}
}
Code: Select all
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon%
;return
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
#include <AutoHotInterception> ; ! ! ! Without this external library AHI Scripts won't work.
#include <TapHoldManager> ; ! ! ! Without this external library THM Scripts won't work.
#include <InterceptionTapHold> ; ! ! ! Without this AHI Scripts won't work.
#UseHook ;For Remote Desktop to work.
AHI := new AutoHotInterception() ; Initializing Interception
ITH1 := new InterceptionTapHold(AHI, keyboardId) ; Initializing Interception Tap Hold (ITH)
;ITH1.Add("L", Func("Func1")) - I wasn't sure what was happening. I've been toggling this within and outside of the header
keyboardId := AHI.GetKeyboardId(0x1A2C, 0x4094) ; ; Retrieving the ID of the keyboard inside the Windows
;This function begins the process of intercepting each individual key and redirecting the thread accordingly to corresponding conditions inside of the callback function. Keys are empty if there is no specified "IF" condition for them.
AHI.SubscribeKeyboard(keyboardId, true, Func("KeyEvent"))
#IfWinActive ahk_class TscShellContainerClass()
KeyEvent(code, state)
Code: Select all
#Include <TapHoldManager>
thm := new TapHoldManager()
thm.Add("x", Func("XFunction"))
; ======== > any (OTHER) include files not related to THM you may have, has to go below the THM Funciton HERE <========
;~ #Include <Vector>
;~ #Include <FindText>
;~ #Include <ToolTipFM>
;~ #Include <PreventRepeating>
;=================================================================================
XFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){ ; 1tap
SoundBeep
return
}
if (isHold=1) & (taps=2) & (state=0){ ; 2taps & hold, state=0 means it beeps only when 'x' is released.
; state=1 means it beeps when pressed down.
SoundBeep
SoundBeep
return
}
}
Hey Steve, thanks for the response! I tried that format and no dice. I did rearrange the code on my header and I'm not getting error messages anymore, but the script doesn't do anything sadly.SteveMylo wrote: ↑16 Feb 2022, 18:26@BeerBread Hi, I don't use AHI or anything else like that, so that may be the cause of your troubles, but I write out THM taps in a 'newer' fashion for taps. if (isHold=0) & (taps=1) & (state){
Not sure if this will be any help for you at all, but its' Structured like this.Code: Select all
#Include <TapHoldManager> thm := new TapHoldManager() thm.Add("x", Func("XFunction")) ; ======== > any (OTHER) include files not related to THM you may have, has to go below the THM Funciton HERE <======== ;~ #Include <Vector> ;~ #Include <FindText> ;~ #Include <ToolTipFM> ;~ #Include <PreventRepeating> ;================================================================================= XFunction(isHold, taps, state){ if (isHold=0) & (taps=1) & (state){ ; 1tap SoundBeep return } if (isHold=1) & (taps=2) & (state=0){ ; 2taps & hold, state=0 means it beeps only when 'x' is released. ; state=1 means it beeps when pressed down. SoundBeep SoundBeep return } }
Thanks! I think I figured it out! I might have to rewrite my whole script to accommodate THM. I keep getting a "Functions cannot contain functions" or, "hotkeys/hotstrings can't be together," errors. Ultimately, this is what a snippet of my code looks like:SteveMylo wrote: ↑17 Feb 2022, 16:46@BeerBread Ok good luck. I'm sure its' a AHI thing and all the others combined. Unfortunatley No one really responds anymore on here ha. I whish they did, THM is the perfect default tool for any hotkey, heck I even use it as a simple Keywait as it solves all issues.
Code: Select all
;return
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
#include <AutoHotInterception> ; ! ! ! Without this external library AHI Scripts won't work.
#include <TapHoldManager> ; ! ! ! Without this external library THM Scripts won't work.
#include <InterceptionTapHold> ; ! ! ! Without this AHI Scripts won't work.
#IfWinActive ahk_class TscShellContainerClass()
#UseHook ;For Remote Desktop to work.
AHI := new AutoHotInterception() ; Initializing Interception
keyboardId := AHI.GetKeyboardId(0x1A2C, 0x4094) ; ; Retrieving the ID of the keyboard inside the Windows
ITH1 := new InterceptionTapHold(AHI, keyboardId) ; Initializing Interception Tap Hold (ITH)
ITH1.Add("l", Func("LFunction"))
;thm.Add("L", Func("LFunction"))
;This function begins the process of intercepting each individual key and redirecting the thread accordingly to corresponding conditions inside of the callback function. Keys are empty if there is no specified "IF" condition for them.
AHI.SubscribeKeyboard(keyboardId, true, Func("KeyEvent"))
KeyEvent(code, state)
{
;===========Direct Bills========Q==========
{
if (state=1) & (code=16) ; This will tab through until you hit the Schedule Number 2000
{
Send,{1}
Send, {tab 5}
Send, {O}
Sleep, 300
Send, {tab 3}
Sleep, 300
Send, {2}{0}0}{0}
Send, {tab}
}
;
;===============Cash Receipts (Both Direct & Agency Bill===========L=======
;if (state=1) & (code=38) ;Experimental - One Tap is for Direct Bills, Two Taps for Agency Bills
LFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){ ; 1tap
Send,{1}
Send, {tab 5}
Send, {O}
Sleep, 300
Send, {tab 3}
Sleep, 300
Send, {2}{0}0}{0}
Send,{tab}
return
}
if (isHold=0) & (taps=2) & (state){
Send,{1}
Send, {tab 5}
Send, {C}
Sleep, 300
Send, {tab}
return
}
}
;
Code: Select all
;return
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force
#Persistent
#include <AutoHotInterception> ; ! ! ! Without this external library AHI Scripts won't work.
#include <TapHoldManager> ; ! ! ! Without this external library THM Scripts won't work.
#include <InterceptionTapHold> ; ! ! ! Without this AHI Scripts won't work.
#IfWinActive ahk_class TscShellContainerClass()
#UseHook ;For Remote Desktop to work.
AHI := new AutoHotInterception() ; Initializing Interception
keyboardId := AHI.GetKeyboardId(0x1A2C, 0x4094) ; ; Retrieving the ID of the keyboard inside the Windows
ITH1 := new InterceptionTapHold(AHI, keyboardId) ; Initializing Interception Tap Hold (ITH)
ITH1.Add("Q", Func("QFunction"))
ITH1.Add("W", Func("WFunction"))
;This function begins the process of intercepting each individual key and redirecting the thread accordingly to corresponding conditions inside of the callback function. Keys are empty if there is no specified "IF" condition for them.
;AHI.SubscribeKeyboard(keyboardId, true, Func("KeyEvent"))
;KeyEvent(code, state)
{
;===============Cash Receipts (Both Direct & Agency Bill===========Q=======
;
QFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){
Send,{1}
Send, {tab 5}
Send, {O}
Sleep, 300
Send, {tab 3}
Sleep, 300
Send, {2}{0}0}{0}
Send,{tab}
return
}
if (isHold=0) & (taps=2) & (state)
{
Send,{1}
Send, {tab 5}
Send, {C}
Sleep, 300
Send, {tab}
return
}
;
;=====================Paste Check# in Description========W=======
;
WFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state)
{
Send,{tab 2}
Sleep, 300
Send,^v
Send,{tab}
return
}
}
;====================
}
yup what he said above.
Code: Select all
QFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){
Send,{1}
Send, {tab 5}
Send, {O}
Sleep, 300
Send, {tab 3}
Sleep, 300
Send, {2}{0}{0}{0}
Send,{tab}
return
}
if (isHold=0) & (taps=2) & (state){
Send,{1}
Send, {tab 5}
Send, {C}
Sleep, 300
Send, {tab}
return
}
}
;
;=====================Paste Check# in Description========W=======
;
WFunction(isHold, taps, state){
if (isHold=0) & (taps=1) & (state){
Send,{tab 2}
Sleep, 300
Send,^v
Send,{tab}
return
}
}
;=
Code: Select all
#include Lib\AutoHotInterception.ahk
#include Lib\TapHoldManager.ahk
#include Lib\InterceptionTapHold.ahk
#Persistent ; Interception scripts may not declare hotkeys, so you may need this to stop it exiting
#SingleInstance force
; Add the VID / PID of the keyboard you wish to filter here
VID1 := 0x04D9, PID1 := 0xA0F8
kb1 := new InterceptionTapHold(VID1, PID1) ; TapTime / Prefix can now be set here
kb1.Add("1", Func("Kb1Func")) ; TapFunc / HoldFunc now always one function
; Un-Comment this to get a list of devices
;devices := kb1.GetKeyboardList()
;Clipboard := devices
;msgbox % devices
Kb1Func(isHold, taps, state){
ToolTip % "KB 1 Key 1`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
Kb2Func(isHold, taps, state){
ToolTip % "KB 2 Key 1`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
Code: Select all
#SingleInstance force
#include <AutoHotInterception>
#include <InterceptionTapHold>
#include <TapHoldManager>
AHI := new AutoHotInterception()
keyboard1Id := AHI.GetKeyboardId(0x04D9, 0xA0F8) ;keypad
ITH1 := new InterceptionTapHold(AHI, keyboard1Id)
;ITH1 := new TapHoldManager()
ITH1.Add("1", Func("Func1"))
ITH1.Add("2", Func("Func2"))
return
Func1(isHold, taps, state){
ToolTip % "KB 1 Key 1`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}
Func2(isHold, taps, state){
ToolTip % "KB 1 Key 2`n" (isHold ? "HOLD" : "TAP") "`nTaps: " taps "`nState: " state
}