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:
Is there a way to do this using autokey?
I'm using Debian 12.
Thanks!
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.