Browse the docs

Key or button held

Passes while a key or a mouse button is held down.

key is held down

Keyboard Maestro: Key (Down, Up), Mouse Button (Pressed, Not Pressed)

Details #

Passes while the key or mouse button you name is being held down at the moment the condition is checked. Give one of key or mouseButton; if both are given, key wins.

key is a virtual key code, a number, not a letter: 0 is A, 49 is Space, 56 is Left Shift. mouseButton counts from 1: 1 is left, 2 is right, 3 is middle, and higher numbers are the extra buttons.

The trace shows the key or mouseButton and whether it was down. For modifier keys alone, Modifier held is easier. Reading the keyboard and mouse is harmless, so it happens for real in a dry run too.

Every condition accepts "negate": true, which flips the verdict. The trace records what was compared before the flip, so a negated condition that blocks a macro still shows the real values.

Conditions in an Only if list combine with all: every one must pass, and an empty list always passes. An if step or a repeat loop takes a match of all (default) or any.

Parameters #

ParameterTypeRequiredValuesWhat it does
keyany valueThe virtual key code to test, as a number (or text that reads as a number).
mouseButtonany valueThe mouse button to test, counting from 1: left, right, middle, then the extra buttons.

Examples #

Is the left button held
Do
  1. If mouse button 1 is down
  2. Show “Left button is down”
  3. Else
  4. Show “Left button is up”
Open in Switchboard to try it

Gotchas #

  • With neither param it fails with inputDown needs a key code or a mouse button.

  • It reads the state at that instant. By the time a hotkey macro runs, the keys that fired it may already be up.

  • It takes a key code, not a key name; look the code up first.

See also #