Browse the docs

Press keys

Presses a key or shortcut, such as ⌘C, Return or F5, optionally several times.

Press keys

Keyboard Maestro: SimulateKeystroke

Details #

Sends a key press, with any modifiers held, to the front app. Use it for shortcuts and for keys that are not text: Return, Escape, arrows, function keys and media keys.

Write the key as a spec in keys. The last part is the key and everything before it is a modifier, joined by +. Names are not case sensitive.

⇧⌘4
cmd+shift+4

Modifiers are cmd (or command), ctrl (control), opt (option, alt), shift, fn (globe) and hyper (all four of ⌘ ⌃ ⌥ ⇧). Glyphs work too: ⌃⌥⌘K. To press the plus key, write cmd++.

Keys you can name:

  • Letters, digits and punctuation, as the character. They follow your keyboard layout, so cmd+z is the key labelled Z even on Dvorak.

  • return (enter), tab, space, delete (backspace), escape (esc), forwarddelete, home, end, pageup, pagedown, help, left, right, up, down.

  • f1 to f20.

  • Keypad keys: keypad0 to keypad9, keypadplus, keypadminus, keypadmultiply, keypaddivide, keypadenter, keypaddecimal, keypadequals, keypadclear.

  • Media keys: volumeup, volumedown, mute, brightnessup, brightnessdown, playpause, nexttrack, previoustrack.

The separate modifiers list adds modifiers to the key. It is the form imported macros use, with one key and a list of modifiers. keys can also be a list of specs, such as ["cmd+c", "tab"], pressed in order.

Presses are 10 ms apart. The output lists the keys pressed and how many times.

Parameters #

ParameterTypeRequiredValuesWhat it does
keysany valueYesRequired. A key spec, or a list of key specs pressed in order.
holdMsnumberHow long to hold each key down, in milliseconds. The default is 0.
modifierslist ofcmd ctrl opt shift fn hyperExtra modifiers, from cmd, ctrl, opt, shift, fn, hyper.
repeatwhole numberHow many times to press it (or the whole list). From 1 to 1000; the default is 1.

Every step also accepts label, onFailure, timeout and dryRunSafe.

Examples #

Select all and copy (really presses keys)
Do
  1. Press CMD+A
  2. Press CMD+C
Open in Switchboard to try it
Scroll down with the arrow key (really presses keys)
Do
  1. Press ↓
Open in Switchboard to try it

Gotchas #

  • An unknown key name fails the step and names the key. A modifier written after the key fails with "the key goes last".

  • Keys go to the front app, so make sure the right app is in front first (Activate app).

  • Media keys act on the system, not on an app.

See also #

Type text, Choose menu item, Hotkey