TapHoldManager - Long Press / Multi Tap / Multi Tap and Hold / Any number of Taps / Multi-Keyboard

Post your working scripts, libraries and tools
User avatar
evilC
Posts: 4337
Joined: 27 Feb 2014, 12:30

TapHoldManager - Long Press / Multi Tap / Multi Tap and Hold / Any number of Taps / Multi-Keyboard

04 Mar 2018, 11:31

This is a handy class library that you can use to double up functionality on keys with long-press and double-tap type functionality.

You create one instance of the class per key you wish to monitor, and it fires one of your functions (not labels! functions only!) when tap or hold events happen

There is a "tapTime" timeout for each hotkey - this defaults to 200ms
When you press a key, if you release it again within 200ms, it is considered a "Tap".
However, more taps could follow, so if the key is pressed again within 200ms, then the tap count increases.
The cycle then repeats, as long as there is no more than 200ms between each tap and release
Once there is no other tap within 200ms, then the tap count stops and your function is fired and passed the number of taps that occurred.

When you press a key (on either the first tap or on a press after a previous tap) and keep it held for 200ms, then that is considered a "Hold".
As soon as this occurs, your hold function is called, and passed the number of taps that happened before the hold, and 1 to signify button down.
Once the key is released, your function is fired again, with 0 to signify up.

Github Page (Documentation here)

Releases Page (Download from here)

Note that TapHoldManager has a variant library that makes it work with AutoHotInterception, which would allow you to respond to Taps and Holds only on a specific keyboard, whilst not affecting the main keyboard. This has been tested, for example, with an Xbox controller keyboard.
Last edited by evilC on 23 Mar 2018, 11:52, edited 7 times in total.
User avatar
evilC
Posts: 4337
Joined: 27 Feb 2014, 12:30

Re: TapAndHoldManager - Long Press / Multi Tap / Multi Tap and Hold, Any number of Taps

04 Mar 2018, 16:58

Examples

Simple Example
Declare hotkeys for the 1 and 2 keys, and route each to it's own function

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Turning Hotkeys On and Off
Before you declare the hotkey, execute Hotkey, If, <your condition>, where <your condition> is code that you would put in an #if statement.
Then, in your code, define an empty #if block that matches <your condintion>
For example:

Code: [Select all] [Download] GeSHi © Codebox Plus

Hotkey, If, toggle == 1
f1Remapper := new TapAndHoldManager("F1", Func("F1TapFunc"))
f2Remapper := new TapAndHoldManager("F2", Func("F2TapFunc"))
return

; Empty #if block for the hotkey, if statement to match
#if toggle == 1
#if
[...]


Multiple Hotkeys (Bound Function Method)
It is also worth noting that you do not have to have one set of functions per hotkey, you can route everything through one set of functions using "bound functions"
Here is the simple example done with bound functions:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by evilC on 23 Mar 2018, 10:32, edited 3 times in total.
User avatar
evilC
Posts: 4337
Joined: 27 Feb 2014, 12:30

Re: TapAndHoldManager - Long Press / Multi Tap / Multi Tap and Hold, Any number of Taps

04 Mar 2018, 17:01

Complete, Useful Scripts

Mapping keyboard to mouse, with acceleration:
Double-tap and hold to move quicker

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by evilC on 23 Mar 2018, 10:40, edited 1 time in total.
User avatar
evilC
Posts: 4337
Joined: 27 Feb 2014, 12:30

Re: TapHoldManager - Long Press / Multi Tap / Multi Tap and Hold, Any number of Taps

23 Mar 2018, 10:22

TapAndHoldManager is now TapHoldManager and is hosted on GitHub

New stuff added:
Ability to configure the holdTime (The time you have to hold a key to trigger a hold) - it defaults to the same as tapTime
Optional parameters can now be set at the manager level, and overridden for individual keys
An add-on is included to make TapHoldManager work with AutoHotInterception, meaning you can respond to Taps and Holds on other keyboards, whilst not affecting your main keyboard.
There is now one callback function, which is passed an isHold parameter, to indicate if the callback is for a tap or a hold

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 27 guests