MACROS: HotKey Multi-Press Templates (inkl. Long-Press) -- Ver 1.2.2

This Topic will be updated from time to time with more Macro-Templates

============================================

UPDATED -- Monday, Feb 28th, 2022 -- 15:20 GMT +1

  • another little Markup for this Post

  • Updates to existing Templates (single Modifier ones)

  • Update to Topic Name - reflecting current Template's Versions

  • Added:

    • Templates with 2 Modifiers
    • Templates with 3 Modifiers

============================================

These Macro-Templates were inspired by the work of Jim (@JMichaelTX) & of
course Dan (@DanThomas) and these Macros:

• Jim’s “Trigger Option Using Long Press of HotKey [Example]
• Dan’s “HotKey Multi-Press Template (Double-Press, Triple-Press, Etc.)

Hey Folks,

I inverted the wheels and decided going a little bit backwards after I recently found a bug in my Templates.

For all of you who had seen this Topic before and all whose are new to this Topic - I will not give up on the Idea providing these Macro-Templates with Local and Instance Variables - but since this is currently eating more of my Time than I can offer on this task at the time I am writing these words - I'll share them with the usage of Global Variables whose will be deleted at the end of each Template.

ReleaseNotes

MACROS: HotKey Multi-Press Templates (inkl. Long-Press) — Ver 1.2.2

Author : @Nr.5-need_Input
MacroType : Template
Ver : 1.2.2

PURPOSE

These Macro-Templates are for unlimited possibilities using just a single KM Hotkey Trigger with multiple Tappings and an additional hold of the Hot-Key after the last Tap was made.

HOW TO USE

• Just Tap your Hot-Key (for Example 5 times) for what should happen with the “Normal Execution“
• Just do the same and keep holding the Hot-Key the fifth time for other things the Macro should do.

Sounds quite simple - and of course yes - it is simple :joy::joy::joy::joy:

Just try and have fun !!

HOW TO SET THESE UP ??!

  • Required:

    • Set a single Hot-Key/Shortcut
    • Set the Value of hkmplp_InterKeypressDelay
    • Set the Value of hkmplp_LongpressDelay
    • Set the Value of hkmplp_KeypressCountLimit
    • Be sure your Hot-Key/Shortcut Trigger matches in the Long-Press Setup

Every Macro comes with 5 predefined Action-Templates whose are disabled by default (Image below).

Info about these Action-Templates from the Macros:

You can choose any of them based on your Setting of the Variable “hkmplp_KeypressCountLimit“ in the above Group “CUSTOM SETTINGS“

You are free in charge on how you want to implement your Actions in one of the Routines after the green collapsed Comment Actions …. Just be aware to choose the right one for your purposes and of course don’t forget to enable your selected one.

You are even free in charge to preconfigurate new Routines staring from 6 Keypresses to any larger number you want.

The rest is just your Imagination. - Have fun !!! :sunglasses::sunglasses::sunglasses::sunglasses:

  • Optional:
    • Set the Value of DND__hkmplp_UseVerifyingScriptAsFile to 1 (enabled)
    • Install the provided ASObjC-Script as compiled Version at a choosen Location and save its Path in the Variable called DND__hkmplp_ScriptPath.

From the dedicated Comment inside the Macros:

!! THESE Variables are needed for the Verifying-SubRoutines in the Long-Press-Setup using AppleScriptObjC !!

The Variable "DND__hkmplp_ScriptPath“ can be used if a locally stored "Compiled Version“ of the ASObjC as "AppleScript-File.scpt“ with the Filename of your chioce is preferred and the Option "DND__hkmplp_UseVerifyingScriptAsFile“ is set to 1 (enabled).

!! IMPORTANT !!
If you decide doing this - keep in mind doing this every Time - otherwise the Path to the compiled script will be lost after the Macro was run.
Also be aware that this Macro gets canceled if you enable the Option "DND__hkmplp_UseVerifyingScriptAsFile“ and leave the Option "DND__hkmplp_ScriptPath“ undefined.
The best option you have in this case is adding the Path to this Template.

If not - Just leave "DND__hkmplp_ScriptPath“ AS IS (EMPTY) - DON’T DELETE IT !! - If the Option "DND__hkmplp_UseVerifyingScriptAsFile“ is set to 0 (disabled) the Long-Press-Setup will execute a build in Version of the Script.

The Variable "hkmplp_ScriptResult“ will be empty until the ASObjC runs… It then stores the Output of the Verification-Process.

Here is the ASObjC Code which is used by the Macro-Templates as "Text-Script":

I've migrated the ASObjC - Code to use Properties. You don't have to do do that.
Just copy the Code to Script Debugger or Script-Editor, compile and save.

Click on this to view the Script-Code

use AppleScript version "2.3" -- Mavericks (10.9) or later
use scripting additions
use framework "Foundation"
use framework "AppKit" -- for NSEvent


--  classes, constants, and enums used
property NSControlKeyMask : a reference to 262144
property NSShiftKeyMask : a reference to 131072
property NSAlternateKeyMask : a reference to 524288
property NSFunctionKeyMask : a reference to 8388608
property NSCommandKeyMask : a reference to 1048576
property NSEvent : a reference to current application's NSEvent


-- Defining the output Strings for each Modifier
set fnKeyStr to "Function-Key down : "
set shiftKeyStr to "Shift-Key down : "
set ctrlKeyStr to "Control-Key down : "
set optionKeyStr to "Option-Key down : "
set cmdKeyStr to "Command-Key down : "


-- Function-Key
set fnKeyStat to (((NSEvent's modifierFlags()) div NSFunctionKeyMask) mod 2) > 0

-- Shift-Key
set shiftKeyStat to (((NSEvent's modifierFlags()) div NSShiftKeyMask) mod 2) > 0

-- Control-Key
set ctrlKeyStat to (((NSEvent's modifierFlags()) div NSControlKeyMask) mod 2) > 0

-- Option-Key
set optionKeyStat to (((NSEvent's modifierFlags()) div NSAlternateKeyMask) mod 2) > 0

-- Command-Key
set cmdKeyStat to (((NSEvent's modifierFlags()) div NSCommandKeyMask) mod 2) > 0


-- Generate the current Output as List
set modifierKeyStat to fnKeyStr & fnKeyStat & return ¬
	& shiftKeyStr & shiftKeyStat & return ¬
	& ctrlKeyStr & ctrlKeyStat & return ¬
	& optionKeyStr & optionKeyStat & return ¬
	& cmdKeyStr & cmdKeyStat

-- Show the List with the current List
return modifierKeyStat

Here is one Example Macro Image (of a "Single Modifier Template") to give you an idea on how the Templates are build. I post only one Image because they have nearly all the same look.

Macro-Image Example (click to view):

Downloads - Section

The Templates for "4 Modifiers / Hyper-Key" aren't ready for uploading yet - I am currently working on them. They'll come as soon as possible.

You'll find all other Combinations below - ready for Download and hopefully all without any Issues.

1.) Macro Group: [HKMPLP] HotKey Multi-Press Templates - 1 Modifier (inkl. Long-Press) Ver 1.2.2

Contents: 4 Macro-Templates (one per Modifier-Key)

  • [Modifier ⇧] HotKey Multi-Press Template - one Modifier (inkl. LongPress) -- Ver 1.2.2
  • [Modifier ⌃] HotKey Multi-Press Template - one Modifier (inkl. LongPress) -- Ver 1.2.2
  • [Modifier ⌘] HotKey Multi-Press Template - one Modifier (inkl. LongPress) -- Ver 1.2.2
  • [Modifier ⌥] HotKey Multi-Press Template - one Modifier (inkl. LongPress) -- Ver 1.2.2

Macro-Group-File:

2.) Macro Group: [HKMPLP] HotKey Multi-Press Templates - 2 Modifiers (inkl. Long-Press) Ver 1.2.2

Contents: 6 Macro-Templates (one per Modifier Combination)

  • [Modifiers ⇧⌃] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⇧⌘] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⇧⌥] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⌃⌘] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⌃⌥] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⌥⌘] HotKey Multi-Press Template - two Modifiers (inkl. LongPress) -- Ver 1.2.2

Macro-Group-File:

3.) Macro Group: [HKMPLP] HotKey Multi-Press Templates - 3 Modifiers (inkl. Long-Press) Ver 1.2.2

Contents: 3 Macro-Templates (one per Modifier Combination)

  • [Modifiers ⇧⌃⌘] HotKey Multi-Press Template - three Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⇧⌃⌥] HotKey Multi-Press Template - three Modifiers (inkl. LongPress) -- Ver 1.2.2
  • [Modifiers ⌃⌥⌘] HotKey Multi-Press Template - three Modifiers (inkl. LongPress) -- Ver 1.2.2

Macro-Group-File:

The Macros were uploaded in a DISABLED state. You must enable them before you can use them.

License/Disclaimer (MIT)

Copyright (c) 2021-2022 Tobias Zittlau

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1 Like

I commend the amount of effort you've put in. I just tried them out and they work great, but even with the delays reduced, they're incredibly laggy (a few seconds) compared to these, so I'm wondering if there's some advantage I'm not aware of that justifies the time they take to run? Is it that you can do one macro with a tap/multi-tap and then perform another macro by holding the last tap? That seems quite a niche use-case to me, but what do I know? Perhaps I've missed some other delay settings that can be reduced, or maybe it's just the lengthy internal processes that my macros don't include that slow the whole thing down. I'm interested to know why there's a separate template for each modifier combination, as I've had no trouble using any key combination with one macro. Either way, beautifully presented.

Hello @noisneil ,

thank you .... appreciate that.

First it was not easy for me to make these - but then after a few days of making Test Macros with the originals I had the Idea combining them and started the work whenever I had the time .....

If you are speaking of the delays in the Macro Options you have to play with the Settings based on how you want to use the Template.

For example, If you want to have 5 presses in total and your Template Setup catches only 3 - you maybe guessed it - the Value of hkmplp_InterKeypressDelay is set to small.

In case of all other delays in the Templates (none of the Calculations) - you have to try out if the Macros continiue to work when you set a smaller Value or disable them. But be aware that maybe whatever you use to set up in the Routines (the Action Templates) - whether a Sub-Macro using only the Execute a Macro - Action or a full Macro Routine - the Macro can abort if your Keypresses aren't catched.

I haven't used your approach yet - but maybe I'll take a closer look on it if I have the time...

Maybe this helps - Since I've read a lot of topics in this Forum and of course in others, too that people sometimes have or had issues in their Macros to catch the Modifier Keys properly - using only the KM native Conditions - I implemented the AppleScript - Routine using ASObjC to Verify if they are pressed or not.

But this should not take to much Time.

First of all - I would call it nifty & niche :sunglasses: :joy:
If you use the Template with 5 Keypresses you have full control of up to 10 Macros - depending on the Way you decide to use the Action-Templates.

Speaking of 10 Macros with only 1 Shortcut you have for Example:

  • pressed 1x = Sub-Macro 1
  • pressed 1x & held down = Sub-Macro 2
  • pressed 2x = Sub-Macro 3
  • pressed 2x & held down = Sub-Macro 4
  • pressed 3x = Sub-Macro 5
  • pressed 3x & held down = Sub-Macro 6
  • pressed 4x = Sub-Macro 7
  • pressed 4x & held down = Sub-Macro 8
  • pressed 5x = Sub-Macro 9
  • pressed 5x & held down = Sub-Macro 10

Here is the Answer:

These Templates are written to work with only 1 HotKey Trigger.

I made one for each combination of Modifiers in use - that the user who use these Templates - has only to think about which Template is to use and then to make sure that the HotKey will Match as the requirements for each Template he or she is using.

Every thing else is depending on Imagination and of course on how the Options are set.

Since I have some plans for improvements and or additional Features / Settings - which I am thinking about from time to time - I am open to any Suggestion you and of course all others may have in Mind.

And because of the fact that you and others are working with Macros whose have a different Routine based on a different HotKey Trigger - I have a Plan to build some Templates for Multiple HotKey Triggers as well...

Let me know if there is still something not clear to you - or if you have Ideas for Improvement.

Stay safe

Greetings from Germany

Tobias

1 Like

Thanks for the brilliantly detailed reply!

Delays: I turned everything I could find either down to very low or off and it still took a few seconds to run, but I'll have another look to see if I missed anything.

I've never heard of modifiers not being caught as triggers... News to me. It'll be in the back of my mind in future. Thanks for the heads up!

Personally, I would find using the same hotkey with numerous tap/hold combinations a bit confusing for most uses, but I can imagine some brilliant uses where it would be quite instinctive. Niche AND nifty I suppose! This is why I use a Stream Deck by the way; it removes the need to think about key combinations.

Is the problem of modifiers being missed so prevalent that it warrants 13 macros? If not for that step, you could just have one, right? Am I right in saying that the reason for having individual macros per modifier set is that each verification script deals with a specific modifier set? If that's the case, could you just add an action to the top of the macro where the user confirms which modifiers they're using? This could then pass them as a variable to your script for verification. This would mean that, should you like to change the hotkey being used to one with different modifiers, you don't have to deal with transferring settings to a different template. You might say, "well, confirming the modifiers is an extra step though", but I'd argue picking which template to use is an extra step, and also means that you have to know what your hotkey is going to be before starting, and you have to commit to it.

image

Hello @noisneil ,

I'll not repeat my self here - but I think I should give you some more explanation how these Templates work.

Depending on these required Options

A Macro build with one of the Templates is instantly locked using a Semaphore Lock and after that it tries to catch how many Times you have pressed your HotKey - what then will be set and verified during a Calculation-Loop based on the Option hkmplp_KeypressCountLimit . This is a process I can't manipulate to run quicker except of the correct setting of the Option hkmplp_InterKeypressDelay - which has to be set to a minimum duration that can be catched on the maximum count of Keypresses - which is set with hkmplp_KeypressCountLimit .

TIP:
What you can try is to check which Settings you have for your Keyboard and maybe play with them to get the right Settings.

Everything else is related to the inner working of KM-Engine and the capabilities of the Mac the Macro is Triggered on.

I think I never said something like that.... - of course Modifiers get cought and you'll get them back as text if you use the TriggerValue - Token . I mentioned the Verifying of Modifiers pressed or not pressed using KM's build in native Conditions.

You're right - it can be very confusing to have such a setup - but at the same time you have more Automation Options for your HotKeys. And if you have something like a cheat sheet where your HotKeys are documented you never get lost.

No. That is not the case. By the way - I think I mentioned it - you will only have to:

  • Choose your Template based on which / whose Modifiers you need
  • Set your HotKey using the dedicated Modifiers (current Version shows the combination only in the Template Name)
  • repeat stting the HotKey in the Long-Press Setup (if you use for example F6 with any Modifier combination it has to be set there, too)

The rest is set depending on the Template you picked.

No I won't do that - because that is not the way the Script works.

Did you see this "use" - Statement:

and these Property-Variables:

The Script uses the AppKit API in Objective-C with the NSKeyMask-References of AppKit`s NSEvent as a Boolean Value (true or false) to indicate the State of each Modifier whose are deprecated since the release of macOS Yosemite (10.10).

You can use them in every Script as long you use AppleScript Version 2.3

In Each of the Template the complete Script is used but only the Depending Modifier Combination is passed in its State back to the Macro.

There will always be the point you maybe like to change HotKeys - and the downs of that is that you then will have to deal with transfering routines ....

I am working on something to automate that Process with KM. But since this is a very complicated to build Tool Set of Macros I don't really know when it is ready for a beta or maybe a finished and stable release.

Greetings from Germany

Tobias

I don't mean to criticise your work; I'm just trying to understand what it is you're doing. I do hope that comes across.

Did you have a look at this? It uses the same keypress counting method and responds to single, double, triple (or more) taps and a long press, but runs very fast.

I apologise for my confusion. Do you mean that sometimes this doesn't work in your macro?
Pasted_Image_13_03_2022__12_50

As you can see, I've given the same problem a fair bit of thought, so this comes from a place of friendly curiosity.

Sure - I got that - everything is fine

Nope - I haven't had the time yet... but I consider to look at your method when I work on the Templates for imporvement - Maybe you're right that I missed something that has to be done in another way.

Yes - That is the native Condition Method I was talking about....

No - not on my Macs ... but I never say never .... there is every time a possible bug that refuse this thing to break.... - And for this case I decided to put in a Scripting Routine checking the Modifier State ...

Damn ! I think - if I am remembering it right - there is something I have to do a rewrite on ....

Greetings from Germany

Tobias

Hi and welcome to the forum!

If you want proper multi-press functionality with KM, a template is essential. KM is brilliant, and forum submissions make it even more so.

Oh, I see. :roll_eyes:

No -- use appropriately sized files for the size and resolution your output requires.

But we're talking different templates here. KM "templates" (and remember, most actions in KM itself are actually templates!) can be really useful, huge time savers, and the user-submitted ones on this forum are often examined, and commented on, in detail by people who know their stuff.

Looks like spam, I flagged it for the moderators.

1 Like

Do love that he's spamming for a site where most of the image links are broken. Looks like the template makers can't fill in a template!

0/10 -- Would not recommend...

1 Like