Synopsis
Description
Thebdg dom pressKey command provides low-level keyboard input simulation:
- Named keys - Support for Enter, Tab, Escape, arrows, function keys
- Modifier keys - Shift, Ctrl, Alt, Meta (Cmd/Win)
- Multiple presses - Repeat key presses with
--times - React-compatible - Proper event dispatch for React applications
- Network stability - Optional wait for AJAX requests to complete
- 0-based indexing - Works with query results or direct selectors
Arguments
CSS selector or numeric index (from
bdg dom query results, 0-based)- Selector:
"#search-input","button.submit","textarea" - Index:
0,1,2(from previous query results)
Key name to press (case-insensitive)See Supported Keys for complete list.
Options
Element index when selector matches multiple elements (0-based)
Press the key multiple times (e.g., press Down arrow 3 times)
Modifier keys (comma-separated):
shift, ctrl, alt, metaExamples: "ctrl", "shift,ctrl", "meta,shift"Skip waiting for network stability after key press
Output in JSON format
Supported Keys
Navigation Keys
Enter- Submit forms, activate buttonsTab- Move to next focusable elementEscape- Close dialogs, cancel actionsBackspace- Delete previous characterDelete- Delete next character
Arrow Keys
ArrowUp,ArrowDown- Vertical navigationArrowLeft,ArrowRight- Horizontal navigation
Page Navigation
PageUp,PageDown- Scroll by pageHome,End- Jump to start/end
Function Keys
F1throughF12- Function keys
Modifier Keys (use with —modifiers)
shift- Shift keyctrl- Control key (Cmd on Mac)alt- Alt key (Option on Mac)meta- Meta key (Windows/Command key)
Special Keys
Space- Space barInsert- Insert keyCapsLock,NumLock,ScrollLock- Lock keys
Printable Characters
Any single character:"a", "Z", "1", "@", etc.
Output Format
Human-readable Output
JSON Output
Examples
Submit Form with Enter
Tab Navigation
Arrow Key Navigation
Keyboard Shortcuts
Escape to Close Dialog
Multiple Key Presses
Use Cases
Keyboard Accessibility Testing
Autocomplete Navigation
Keyboard-Only Form Submission
Game Controls
Key Mapping
The command uses CDPInput.dispatchKeyEvent with the following key codes:
- Enter →
keyCode: 13 - Tab →
keyCode: 9 - Escape →
keyCode: 27 - Backspace →
keyCode: 8 - Arrow keys →
keyCode: 37-40
src/commands/dom/keyMapping.ts in the source code.
Exit Codes
Success - Key pressed
Invalid arguments - Unknown key name or invalid options
Element not found - Selector didn’t match any element
Stale element - Index from previous query is no longer valid
Session not active - Start a session first
Troubleshooting
Key Not Recognized
If you get “Unknown key” error:Element Not Focusable
Some elements can’t receive keyboard events:Modifier Keys Not Working
Ensure correct modifier syntax:Tips
For form submission, prefer
bdg dom submit over pressKey Enter as it handles navigation and network waiting intelligently.Comparison
pressKey vs fill
| Feature | pressKey | fill |
|---|---|---|
| Use case | Keyboard navigation | Text input |
| Supports shortcuts | ✓ Yes | ✗ No |
| Supports arrows | ✓ Yes | ✗ No |
| Fills text | ✗ Character by character | ✓ Full string |
| Navigation keys | ✓ Yes | ✗ No |
Related Commands
Fill Fields
Fill form fields with text values
Click Elements
Click elements instead of using Enter key
Submit Forms
Smart form submission with waiting
Forms Guide
Complete form interaction workflows

