Long Press USB Device Key - Working Example

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.


Here's the macro that needs to be included in the above example:

Download:
Long Press Macros.kmmacros (6.8 KB)

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...

-g-

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.

G

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.