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.
cmd+shift+4Modifiers 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+zis 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.f1tof20.Keypad keys:
keypad0tokeypad9,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 #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
keys | any value | Yes | Required. A key spec, or a list of key specs pressed in order. | |
holdMs | number | How long to hold each key down, in milliseconds. The default is 0. | ||
modifiers | list of | cmd ctrl opt shift fn hyper | Extra modifiers, from cmd, ctrl, opt, shift, fn, hyper. | |
repeat | whole number | How 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 #
- Press CMD+A
- Press CMD+C
- Press ↓
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.