Double Tap Control


#1

Keyboard Maestro supports double tapping a modifier key by using the USB Device Key trigger.

Double Tap Control New.kmmacros (2.2 KB)

Prior to version 7.0, Keyboard Maestro did not support the tapped twice modifier for Hot Key and USB Device Key triggers, but there are two ways you can accomplish this if desired. Either way, you use a USB Device Key trigger to trigger on the press of the control key.

The first way is to keep track of the time the macro last fired, and only perform the macro if it was fired recently.

The second way is to have two (or more) macros, only one of which is enabled. The first one simply disables itself and enables the next one, pause a while, and then enables itself and disables the second one. The second one disables itself, reenables the first one, and then performs the action.


How are multiple tap triggers possible?
Question to hot key triggers
#2

It works for me but I would want to get a little more understanding.

What is the variable LastControl and NowControl and what does mean “- 1.0” in this context?

Below is my macro:


#3

The macro is very simple if you know any programming languages at all. If you were going to write this in a text programming language, it would look something like this:

NowControl = SECONDS(); // get the current time in seconds since boot.
if LastControl == "" then
    LastControl = 0; // if the variable LastControl is undefined, set it to 0
end-if
if LastControl > NowControl - 1.0 then // if the last tap of the Control key happened less than 1.0 seconds ago
    DoStuff();
end-if
LastControl = NowControl; // remember the time this tap of the Control key

Keyboard Maestro is simply a visual programming language. Ironically, I’d not actually in favor of visual programming languages for most purposes because, as seen above, the text version is not much harder to understand. The reason it works well in Keyboard Maestro is that the programming aspect is an addition, allowing you to stretch and amplify the power provided by the actions, and the actions in turn get a lot of power from their visual editing that would be much more challenging to do in a textual programming language.

So to answer your specific question:

The variable LastControl remembers the time at which you last tapped the control key (the last time this macro was run). If you made another version of this macro (eg Double Tap Command) you would need to use a different variable.

The variable NowControl is a temporary variable that holds the current time. It’s no longer needed as you could use the TRIGGERTIME() function instead - if LastControl > TRIGGERTTIME() - 1.0.

The “- 1.0” is “1 second ago”. It is the allowable amount of time for it to be considered a double tap of the control key as opposed to pressing it, waiting and then pressing it again.


Keystroke: Option Key Only
#4

So I have a problem with this macro.

For example, I set up right Shift as the key, and when I just write regularly (I mean using Shift key), KM will trigger the action.
Example: I called to Suzy.

What should I change?


#5

The “1.0” is “1.0 seconds”. It is the time allowed between the first and second press.

If you type two shift keystrokes within 1.0 seconds when typing normally, then it will appear as a double tap.

Reduce the 1.0 to a smaller number - as small as possible while still recognising your double tap when you use it.


#6

Updated to use the version 7 tapped twice facility.


#7

Can this be modified to work with internal Macbook keyboard or Bluetooth keyboard?


#8

Probably not, it only works with USB devices. The internal keyboard may or may not be a USB device. A bluetooth keyboard probably isn’t.


#9

@peternlewis Hi Peter, I've been using this double tap trigger very often for nearly 3 months, but recently (probably from last month) it stopped working whenever I put my Mac to sleep mode or screen saver mode. I had to unplug and replug the cable of my keyboard to get this trigger working right every time.

PS:
Keyboard Maestro version: 8.2.4 (newest up to now);
macOS system version: 10.13.6 (newest up to now).


#10

@peternlewis Never mind~ After restarting the Mac, it works now (Don't know why the previous restarting doesn't work though )