Syntax
Description
Holds down a key or modifier without releasing it. This is useful for complex input sequences where you need to maintain a key press while performing other actions, or for simulating sustained key presses. The key remains held until you explicitly callkey-up with the same key or modifier.
Parameters
Key or modifier to hold down. See Key Combo Format below for syntax.
Key Combo Format
Single Modifiers
Single Keys
Modifier Combinations
Modifier Aliases
cmd,command→ Command/Windows keyctrl,control→ Control keyalt,option→ Alt/Option keyshift→ Shift key
Response
Success Response
Error Response
Examples
Hold Shift for Multiple Selections
Simulate Drag with Space Bar
Some applications use space+drag for panning:Hold Modifier for Keyboard Shortcut Variations
Multi-Modifier Hold
Error Codes
| Code | Description |
|---|---|
INVALID_ARGS | Invalid key format or unknown modifier |
ACTION_FAILED | OS rejected the key-down event |
PERM_DENIED | Accessibility permission not granted |
Notes
- Always pair
key-downwithkey-upto avoid stuck modifier states - If your script exits unexpectedly with keys held, the OS may keep them in the “down” state until manually released
- Held modifiers affect all subsequent input (clicks, typing, etc.) until released
- The command returns immediately; it does not wait for a key-up event
Best Practices
Use Try-Finally Pattern
When scripting, ensure keys are always released:Avoid Long-Running Holds
Release keys as soon as possible to avoid interfering with user input or other automation.Match Down and Up Calls
If you holdcmd+shift, release with the exact same combo: