Controlling Which Macros Are Fired When Tapping Once, Twice, Thrice, or Four Times

Hello,

@peternlewis, @DanThomas, and @JMichaelTX

Is it possible for us to create programming and pin it somewhere easy to see in the Wiki to ensure that only the macro assigned to the final tap is fired? KM doesn't need a "prescience API", it just needs a pause feature. Pinned programming would help each newcomer, like myself, so each newcomer doesn't have to reinvent the wheel for a powerful base function.

Again, I know timing and the individual actions will have to change, but at least the pause, do first, etc, is all built.

I posted my programming attempt below based on something @peternlewis posted

Just for test purposes, I'm attempting to insert text into a simple text document "macro a. " for macro a, "macro b. " for macro b, and "macro c. " for macro c. I'm using position click to activate the text document before KM "types" the text, so you may have to adjust the position. Macro a keeps firing over and over again.

@DanThomas I did not attempt this macro because I did not understand it. Also it seemed like it was using a keyboard input, introducing the addition problem of "key swallowing". Also, it was from a long time ago, I'm wondering if KM updates have replaced some of the functionality.

I'm attempting this with an xKeys, which I believe doesn't have the swallowing issue. Although I'm guessing any pinned programming would benefit from addressing "key swallowing" as well.

What's the fastest, simplest, most reliable way to do this?

  1. Tap once on an xKeys, KM pauses for .2 seconds, if no other tap occurs, do Macro A
  2. If another tap occurs, pause .2 seconds, if no other tap occurs, do Macro B,
  3. Pause .2 seconds, if no other tap occurs, do Macro C,
  4. Pause .2 seconds, if no other tap occurs, do Marco D.

If possible could you upload the actual actions programmed, or adjust my programming below and repost?

Here is my attempt. This is using "set variable to text", but is that the best? Why not parameter, or why not some of the other posts that do a key count, keeping track of how many key taps, etc?

Thanks!

Double_Tap_Test_Letter_Only Macros (v9.2)

Double_Tap_Test_Letter_Only Macros.kmmacros (13 KB)

It doesn't require keyboard input - any trigger would work. But if you don't understand that macro, with the instructions I included, and didn't even try to see if it might work, then I doubt anything else I could come up with would be helpful, so I hope someone else can solve your problem.

I don't understand your comment. Doesn't xKeys "taps" work just like "tapping" any key on the keyboard?

I think you should download and test @DanThomas' macro. Seems to me it does exactly what you are asking for:

Hello,

@DanThomas I'm sorry if I've offended you. I didn't mean to. I did download your build, I just didn't understand it exactly.

But If @JMichaelTX says its complex and he can't figure out the logic, and you say you couldn't explain it, can you see how a noobie might be a bit intimated by it?

Also, when I downloaded your macro, I tried to look up some of the actions, but there doesn't seem to be a match in the Wiki:

In my limited understanding, It looked like you built a predecessor to the now built in tapping feature for triggers. Was your macro built before v7? Also, if the actions don't appear in the wiki it made me think they may not be there anymore.

In any case, I was hoping four years later there was a simpler solution.

@JMichaelTX regarding swallowing keys, I thought I read on the forum that there was a difference between keyboard keys and usb devices like xKeys. I don't really know.

If you guys think this is the best way to introduce a pause and wait for another keystroke before firing a Macro, I'll attempt all the variables.

Thanks!

It is somewhat of a complex macro, and at the time I just didn't want to spend the time to understand it. I still believe that @DanThomas' macro is your best starting point, and may even do exactly what you need. So you can either start from scratch, or put the effort you need to understand his macro. You will likely learn a lot.

Hey Ernest,

hkmpKeypressCount is a variable name made up by @DanThomas for this particular macro – so there's no reason you would find it in any of the Keyboard Maestro documentation.

How Are Multiple Tap Triggers Possible?
Keyboard Maestro Wiki ⇢ USB Device Key

I think you are misunderstanding what “key swallowing” means.

Your device key is essentially a keyboard chord – when you press that chord Keyboard Maestro will eat it – e.g. it will not be output anywhere else.

No matter how many times you press the chord, it will be eaten by KM.

When you try to have multiple macros with tapping triggers using the same key, the one with the fewest taps will step on all the others.

What Dan's macro does is allow you to tap a given keyboard shortcut or device trigger multiple times in quick succession. (You can adjust the delay time the macro allows between trigger presses.)

The macro counts the number of keypresses and stores that number in a variable.

You can then use the number to control a Switch or Case action to perform different tasks according the value of the number.

HotKey Multi-Press Template ⇢ Mod by @ccstone v1.00.kmmacros (33 KB)

I've added the action in RED to Dan's macro. You can press the trigger up to 3 times to give different results – by way of demonstration. You would replace the display-text actions in the switch-action with your various tasks.

There are other methods for macros that could give similar results via different means.

Conflict Palette
Prompt for User Input action with keyboard shortcut assigned to buttons.

But for your stated purpose I think Dan's macro is going to be your best bet – provided the keyboard shortcut can be successfully replaced with your device trigger.

-Chris

1 Like

Hey @whitebalance ,

what @ccstone said is absolutely the right way of @DanThomas 's Template will work.... but there is not just the Switch/Case Action where you give the Macro the definition what to do with each tapping... YOU MUST INCREASE THE TEMPLATE checking EVERY KEYTAP using the Pause Until Action with any instead of all and this followed by IF/THEN Action also using any .

In Theory this means:

  Tap 1
    * Var "Count" = 0
    * Pause 0.2
    * Pause Until any
       * Key Down ---> maybe first Tapping 
       * Key Up
    * IF/THEN any
       * Key Down ---> Here is first Tapping set !!! 
       * Key Up
         * Nested IF/THEN  ---> Key Down
            * Var "Count" = 1
            * Pause 0.2
            * Pause Until any ---> looking for maybe second Tapping
                * Key Down ---> possible new Tapping (here second) ??
                * Key Up ---> nothing - Var has not to be canged to 2
            * Nested IF/THEN any --->
                * Key Down ---> Here is the second Tapping set !!!
                * Key Up .....
                * .........
         * Nested IF/THEN in OTHERWISE ---> Key Up
            * ........

Note: Just the theory ... but here you see the case .... you have to set up every thing and you have to be sure the Macro is checking every time if there is another Tapping or not so that you have the Var Output = 3 when you are Tapping 3 Times....

the Var Output then is swithed in the Macro ---> Here you set up what to do

I hope this will help you understanding how the Template works...

Greetings from Germany

1 Like

You didn't offend me, but I admit that my response wasn't a lot of help.

Good point. Even with all my experience, sometimes I still forget that not everyone sees things the same way I do.

With that said, it's really easy. There's only two things you need to do to use this template:


1) Set the options

image

Define how long to allow between key presses, and how many key presses you want to handle.

So you might want to change it to this:

Giving you a maximum of .2 seconds between presses, and a maximum of 3 consecutive presses.


2) Handle the results

Replace the "Prompt" action at the end, with a switch statement like this:

Replace the "Comment" actions with whatever you want to do.

That's it.

1 Like

That's not correct. See my previous reply, above.

Hey @DanThomas, @JMichaelTX, @ccstone, and @Nr.5-need_input,

Thank you for all the support on this macro. It will really improve my workflow. On a gig right now, I'll give it try later today, and let you know how I do.

Thanks again!

No problem. Hope your gig goes well!

Ahhh --Thank you @DanThomas ,

think I got it ... maybe I was completely wrong today ... I'm sorry I misunderstood the template.... have read a lot of stuff the last days..... but i think it goes to @JMichaelTX 's Long Key Press - Template Macro what i've written here...

Hello @DanThomas, @JMichaelTX, @ccstone, @Nr.5-need_input,

I couldn't help myself, I had to take a break and try this.

It worked!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Hot damn, it worked.

I have no idea how its passing variables, or how the semaphore works, but I'll take it apart soon and try to understand it.

@DanThomas, was I right you built this before tapping multiple times was built it? I just have to leave it in tap once. It's just as fast as the built in multi-tapping. Not to get greedy, but do you also have something that cycles through actions after each keystroke instead of waiting for keystrokes?

@ccstone, I'm sure I just have to look harder, but it was your last addition at the bottom that allowed me to see were my actions go.

With consistent ordering of modifiers and tapping I can have one key on a 128 button xKeys launch every version of a GUI configurations for a particular operation like Curves. 21 "buttons" down to 1. Using that same ordering for other actions, muscle memory will be a snap for so many functions.

Thanks to all!!!!!!!!!!!

1 Like

Sounds just like me.

Awesome! And yes, this was way before multi-tapping was added - I didn't even know Peter added that feature.

There's comments throughout the macro that may help.

The concepts involved in this macro are difficult to understand, so if you don't "get it", don't feel bad - they're advanced programming concepts. But here's the gist:

  1. One macro can actually be running multiple instances at the same time. In other words, if a macro is launched by a hot key, and it doesn't finish running before the hot key is pressed again, then a second instance of the macro starts running simultaneously.

    This is a tricky thing to wrap your head around, so you may have to think on it for a while. I suspect some people may never be able to understand this - like I said, it's an advanced-level programming concept.

  2. But if you do understand #1, here's the really mind-blowing part: If one instance of the macro makes changes to a global variable, that change affects the other instance.

    This can cause some really strange things to happen. For example, if you were using a global variable to count the number of times you were going through a loop, and another instance starts running, the counter could get severely confused.

    That's actually why Peter implemented Local and Instance variables. If a second instance of the macro sets a Local or Instance variable, it only affects that instance.

This is all really confusing, I know, and you don't really need to understand it to use the template. If, however, you do manage to wrap your mind around this, then you may have other questions, so feel free to ask. :grinning_face_with_smiling_eyes:

Nyet.

There's a discussion with Peter about the multi-tap-trigger several months, before @DanThomas posted the macro.

-Chris

Hey Guys

Again - I'm sorry for yesterdays post...

I have a question for using this template - @DanThomas , @JMichaelTX or @ccstone

Is it possible using this Template to set up for neither detecting in normal mode or for holding down the key ?

I am asking because I have set up my key as a Hyper-Key with Karabiner Elements....

If there is a way to accomplish this – how do I have to do that ??

My Idea looks like this 

Hyper-Key
     Tapped 1x ---> EveryDay Favorite 1 
     Tapped 2x ---> EveryDay Favorite 2
     Tapped 3x ---> EveryDay Favorite 3

Normal use 
     Tapped 1x ---> Once a Week 1 
     Tapped 2x ---> Once a Week 2
     Tapped 3x ---> Once a Week 3

This maybe will be a great feature - NOT ONLY FOR ME – I think many others who use the key as a Hyper-Key will be glad if ther is a way to do this ...

Many Thanks

Greetings from Germany

I don't really understand what you're asking. What does Hyper-Key have do do with it - I thought Hyper-Key just turned something like your shift key into another keystroke?

Hello @DanThomas ,

Sure it can be something like that.... but in my case is not SHIFT the Hyper-Key - it's my CAPSLOCK.

So I can use my CAPSLOCK with one Finger for all 4 Modifiers .... I want to have a Macro Routine running when I press Hyper + A which is different to A

... Is that doable with your Template ??? - or is there something I am missing??

Hey Tobias,

Some people on the forum are using a hyper-key, but I don't and nor do Dan or JM.
So we can't tell you if it will work or not.

Why don' t you just test it out and see?

Then report back.

-Chris

My template is just a standard macro. It triggers like any other macro. So it's up to you to figure out how to trigger it.