Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Multi-tap and/or tap-and-hold behaviour possible?

26 views
Skip to first unread message

Stathis Athanasiou

unread,
Apr 24, 2024, 8:24:01 AM4/24/24
to autokey-users

I can't find a way to use multi-taps and/or tap and hold keys on the keyboard using autokey.

On Windows using AHK and TapHoldManager, I can do the following:

  • Tap key on keyboard > action 1
  • Double tap key on keyboard > action 2
  • Tap and hold key on keyboard > move mouse and hold left mouse button until I release the keyboard key
  • Double tap and hold key on keyboard > move mouse to a different position and hold left mouse button until I release the keyboard key

Is there a way to do this using autokey?

I'm using Debian 12.

Thanks!

Joe

unread,
Apr 24, 2024, 12:15:53 PM4/24/24
to autoke...@googlegroups.com

Welcome to the AutoKey community, Stathis!

It's not impossible, but it's not easy.

To do anything like that, you have to write a somewhat involved script.

Here are some general ideas of how to go about it.

If one key is your hotkey, then your script will be launched each time it is pressed. Multiple instances of your script will be running concurrently.

The first thing to do is to get the current time. You then retrieve an AutoKey saved variable (last) with the time the script last ran and compare it to the time now. If the difference is within your tolerance, then you have detected a double tap or a triple tap. You would then increment and save the number of taps detected (taps).

If the difference is too long for a multi-tap, then taps is the number of taps you detected. Use it to determine what to do next. Then set it back to to 0 or 1 and save it. Save the current time in last so you're ready to detect the next multi-tap event. Then you have a case statement or other flow control logic based on taps.

With a multi-tap, there are some issues. First, your first one or two running instances of your script can't do anything further before waiting long enough for subsequent taps to occur. If taps is greater than 3, you have to decide what to do - probably just terminate.

Second, when they do occur, only the most recent running instance of your script should do anything. The other instances need to terminate. You probably need another variable that these scripts retrieve that says you're not the last, go away. Maybe the script can keep its value of taps and then read it again after a while. If it is larger that their value they need to terminate. If it's not, they can go ahead and run and then reset the number of taps. For triple taps, this has to happen twice, so the first instance terminating has to do it without confusing the second instance that also has to terminate.

You probably need to construct a state table for all the sequences (states) that can occur and what should happen in each state before trying to code this. It's a bit of a finite state automaton.

"taps" and "last" are arbitrary saved variable names I used for this example.

The first time your script runs, taps and last will be undefined. Undefined means the last tap was too long ago. You have to handle the exception that occurs when you try to retrieve the value of a stored variable that does not exist yet.

As I said, not impossible, but... :)

You should definitely have some experience writing and debugging simpler AutoKey scripts before attempting this one. There's no rocket science involved, but you have to get the sequences of events and variable values just right.

Since your hotkey will probably be a simple key that you need to use normally elsewhere, you should probably use a window filter so that your script is only triggered in windows where it is needed.

If you do attempt it, we can assist as you go, but it would be better to do that on Gitter https://gitter.im/autokey/autokey because it supports markdown and you can post code blocks that won't get reformatted like those in email/forum posts usually do. It even does color syntax highlighting if it knows what language the code is written in.

We can also use a discussion thread, so only interested users will see all the details.

Once you do get it to work, you can add it to our wiki for other brave souls to benefit from. :)

Out of curiosity, I looked up your name to see what country you might be from. Are you the film director? (feel free not to answer)
I'm not aware of any public figures who use AutoKey. That would be cool.

Joe

--
You received this message because you are subscribed to the Google Groups "autokey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autokey-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autokey-users/95e459ef-2f8e-47c9-ae3c-9700f1b805bcn%40googlegroups.com.

Stathis Athanasiou

unread,
Apr 26, 2024, 7:03:07 PM4/26/24
to autokey-users
Hi Joe,
thanks so much for this masterclass in autokey, I really appreciate it!

Yes I'm the film director from Athens, Greece. However back in the day I was probably the first kid to own a ZX Spectrum in Athens circa 1983, so starting from BASIC, I always was messing with code and computers. However this is overwhelming for me. I understand the principles of what you explained, but it's way out of my league with regards to implementing it. I'll get in touch with a developer friend of mine and see if we can build this together, and I'll let evryone know of our progress.

My use case for this and what I've already done in Windows with AHK and the TapHoldManager extension, is to control Davinci Resolve, where by pressing and holding a key, locks the mouse in one control which can be adjusted using the trackball. It is a very efficient way of working once you build muscle memory, and I'm trying to recreate it in Linux, because I want to ditch Windows for good, and little things like this are very important for me to do the jump.

Thanks again and I'll get back if I make progress with the script.

Reply all
Reply to author
Forward
0 new messages