Background: Since ControllerMate isn't compatible with Catalina, I needed to bring its functionality into Keyboard Maestro. The only thing I was having trouble with was long presses with keys on an X-Keys USB keyboard. The current examples out there seem to only work with qwerty keyboards. Here's my solution. Hope it helps.
Create a macro that requires short and long press actions with the same key. Add an Is Pressed trigger to the USB device key (or regular keyboard key combo). Also add an Is Released trigger for the same key. Add the Long Press macro and an If Condition to see if the LongPress variable is yes or no.
If the key is pressed and released within 0.5 seconds, the short press actions are played. There's also a benefit of no delay. If the key is released after 0.5 seconds, the long press actions are played immediately upon release. The example uses Control + Option + Command + L, because I wanted the example to work out of the box. Change the triggers to your USB device key as needed.
This is an excellent set of macros -- thank you for putting this online (fellow X-key user). Is there any way for the macro to automatically execute the 'LongPress' once the time specified has expired, rather than waiting for the device key to be released? I am attempting to replicate a power button on an old keyboard that wouldn't activate unless it was held for 2+ seconds; then the Shut Down, Reset, Sleep dialog would appear...
Good to know that someone else has benefited from these macros. It seems like KM can't track how long a USB device key is held down. That's why 'is released' is the secret sauce to getting this working. I could be wrong. If anyone knows better, post a reply. There are a few unsuccessful attempts using key press timeouts still in my macros list.
You could modify the Long Press macro to have a 2 second duration. It would still be on release, but would technically work.
I did edit it to 1.5 seconds, and used a terminal command to get rid of the All Macros Cancelled notification. Before I decided on Keyboard Maestro, I played around with a few different solutions (not on Catalina yet, so I can still fool with ControllerMate), including hardware programming mode on a PC. One curious 'feature' I discovered was that if I plugged the K-key device into the usb hub of my Mac's keyboard it will allow hardware programmed keys, even the restricted ones, to pass through without complaint (I have been trying in vain to get F14/Scroll Lock simulated, as the KVM I use looks for [Scroll Lock] + [Scroll Lock] + [Delete] as a trigger to cycle through the computers). The only problem is that all the other X-Key buttons paired to Keyboard Maestro macros do not get consistently registered, so it might take three or four presses to get them to fire. I am curious if you could register one of the X-Key devices as a keyboard (via their endpoint encoding) so that restricted keys would be allowed when programmed in hardware mode... more experiments for another day.
I should have mentioned that terminal command in my original post. Maybe I will update it as some point. Those notifications can get annoying without it.
The only hardware programming I have done from a PC was to turn off all of the key lights. That PC interface is horrible.
It was mentioned in the forum that there's an F key limitation in KM. Not sure when that started. It worked in High Sierra, but I skipped Mojave and went straight to Catalina.
What is the purpose of the "Cancel All Macros" action in your macro? Surely it doesn't need to cancel ALL macros? What are the macros that are specifically needing to be cancelled here, and why? I'm just trying to better understand this macro. It seems like you could just use "Cancel Just This Macro" to cancel just that specific macro, or use "Cancel This Macro" to cancel that specific macro and its parent macro. I'm still trying to figure out the purpose of this, but it seems like you wouldn't need to cancel ALL macros. Thanks for helping me understand.
Also, thanks for the useful macro. I've been looking around for a more "simple", snappier long press/short press trigger macro, as I don't need all of the multipress/multitap stuff, and your macro seems to do the job. I just wanted to better understand the Cancel All Macros thing.
My X-Keys 80 key keyboard stopped being detected in modern macOS versions. Firmware update wouldn't fix it either. It is working now, but had to modify X-Keys' Swift app from their GitHub. The Swift app now triggers KM via a shell script. Thus, I had to create a new way to handle long presses. So, I'm not using that original Long Press macro anymore.
It's been a while since I messed with it. I believe that the Long Press macro had to cancel the macro that called it when pressed. Then, it would perform the appropriate action when released, whether it was a long or short press. Try changing it to Cancel This Macro. I think it will still work as expected. I probably just didn't know any better back then, and it didn't affect the way I used KM.