> For the complete documentation index, see [llms.txt](https://docs.zerowork.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zerowork.io/using-zerowork/using-building-blocks/keyboard-action.md).

# Keyboard Action

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FdoiGtoiXGs0V9Yn5VN0l%2Fkeyboard_action_block.png?alt=media&amp;token=457654e3-8dfb-4a97-8bd7-3fdad4c82b6d" alt="" width="375"><figcaption></figcaption></figure>

The **Keyboard Action** block presses keys on the keyboard: a single key like <kbd>**Enter**</kbd>, <kbd>**Tab**</kbd>, or <kbd>**Escape**</kbd>, or a shortcut like <kbd>**Ctrl/CMD**</kbd> <kbd>**C**</kbd> keystroke combination goes to whatever is currently focused on the active web page.

{% hint style="info" %}
This block sends keystrokes to the **active web page** your TaskBot is automating, not to the machine your TaskBot is running on. This block can't control the desktop, other applications, the operating system, or the browser's own windows and menus. The keypresses you configure within this block only reach the focused element on your TaskBot's active web page.\
\
ZeroWork also supports everything *this* specific block doesn't; consider using a [Write JavaScript](/using-zerowork/using-building-blocks/write-javascript.md) block if you need to automate something outside a web page. See [Things To Know](#things-to-know).\
\
Alternatively, to type text into a web page, use an [Insert Text or Data](/using-zerowork/using-building-blocks/insert-text-or-data.md) block.
{% endhint %}

{% hint style="success" icon="lightbulb" %}
Can't figure out a CSS selector or XPath for a [Click Web Element](/using-zerowork/using-building-blocks/click-web-element.md) block? You can often simply skip it. In a single Keyboard Action block, press <kbd>**Tab**</kbd> as many times as it takes to reach the web page's element, then <kbd>**Enter**</kbd> to activate a link (or <kbd>**Space**</kbd> to press a button or tick a checkbox).\
\
The Keyboard Action block needs no selector at all.\
\
See [Things To Know](#things-to-know).
{% endhint %}

## How To Use It

<figure><img src="https://3220183989-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9LcR8XM7TGOzOCDGsCS%2Fuploads%2FAWoaRHpLP8sfA9QCf1QK%2Fkeyboard_action_settings.png?alt=media&amp;token=eb8c658d-6a51-477d-bd7c-306603b1ebf7" alt=""><figcaption></figcaption></figure>

Click into the field (*"Press a key on your keyboard"*) and **press the key or combination** you want to send on your keyboard. It's captured as you press it and shown back, for example <kbd>**Shift**</kbd> <kbd>**Tab**</kbd> or <kbd>**Ctrl**</kbd> <kbd>**C**</kbd> .

Click the **Save** button to close this block's configuration and release keyboard control back to you.

{% hint style="success" icon="lightbulb" %}
**Order matters for a keyboard shortcut**\
\
When using keyboard shortcuts that use multiple keys add the modifier first, then the key (e.g. <kbd>**Shift**</kbd> then <kbd>**Tab**</kbd>, not <kbd>**Tab**</kbd> then <kbd>**Shift**</kbd>)
{% endhint %}

#### Block-level Delays

**Min sec** and **Max sec** represent a pause after the keys are pressed, before the next block runs. The wait is randomized between the two values, and setting both to the same number makes it fixed. This block defaults to **1 second**.

{% hint style="info" %}
See the [Delay](https://docs.zerowork.io/using-zerowork/using-building-blocks/delay) block for how these two fields behave, including decimals, references, and what happens when a field is left empty. See [Delay Times between the Building Blocks](https://docs.zerowork.io/using-zerowork/using-building-blocks/building-block-options/delay-times-between-the-building-blocks) for how block-level delays fit into a TaskBot's run.
{% endhint %}

## Things To Know

* **Focus first because keystrokes go to whatever web page element is active.** This block doesn't allow you to specify a CSS selector or XPath, so the keystrokes hit wherever the cursor already is, or whatever element you're already focused on. First click into a field with a [Click Web Element](/using-zerowork/using-building-blocks/click-web-element.md) block, or insert text with an [Insert Text or Data](/using-zerowork/using-building-blocks/insert-text-or-data.md) block, or change the focused page element with a <kbd>**Tab**</kbd> into it before pressing keys with this block. Without doing so, the keypresses within this block may land nowhere useful.
* **`body` is a valid selector; handy for focusing the whole web page before using this block.** Some keys act on the page rather than a field, like <kbd>**PageUp**</kbd> / <kbd>**PageDown**</kbd>, or <kbd>**Space**</kbd> to scroll. If you need to use this block to operate on a *page*, consider using a [Click Web Element](/using-zerowork/using-building-blocks/click-web-element.md) block with `body` as its CSS selector prior to it.
* <kbd>**CMD**</kbd>**&#x20;and&#x20;**<kbd>**Ctrl**</kbd>**&#x20;adapt to the operating system your TaskBot runs on.** Keyboard shortcuts you set with <kbd>**CMD**</kbd> on a Mac automatically work when your TaskBot runs on Windows or Linux; ZeroWork automatically maps <kbd>**CMD**</kbd> and <kbd>**Ctrl**</kbd> to each other so they match the operating system your TaskBot is running on. You don't need separate versions per environment or OS.
* **One block can run a whole keyboard sequence.** The keys play in the order you press them, so a single block can repeat a key. For example, <kbd>**Tab**</kbd> <kbd>**Tab**</kbd> <kbd>**Tab**</kbd> moves through 3 form fields or web page focusable elements. If you're working with many same repeatable keypresses, consider wrapping this block in a [Start Repeat](https://docs.zerowork.io/using-zerowork/using-building-blocks/start-repeat) loop instead of capturing the key over and over within a single Keyboard Action block; you don't need a Keyboard Action block that contains 42 <kbd>**Tab**</kbd> keypresses if you have one Start Repeat block before this one that simply uses a fixed number of 42 iterations.
* **A modifier key stays held for the rest of the block and doesn't let go mid-sequence.** ZeroWork lets you shortcut your keyboard shortcuts because every key after a modifier key like <kbd>**CMD**</kbd> (or <kbd>**Ctrl**</kbd>) is combined with it. For example, <kbd>**CMD**</kbd> <kbd>**A**</kbd> <kbd>**C**</kbd> in this block will do 2 things at once: select all, then copy that selection to your machine's clipboard. This also means that keys you might have meant to press plain (without a modifier) still carry the modifier you used, (for example <kbd>**CMD**</kbd> <kbd>**A**</kbd> <kbd>**X**</kbd> selects all and then **cuts to the clipboard** instead of typing the "x" character). When you need an unmodified key after already using a previous modifier key in this block, or when you need to use another keyboard shortcut that uses a *different* modifier key than you used earlier in this block, start a new Keyboard Action block.

### Web Page Keyboard Shortcuts

**Keys that work inside the page** (what's actively focused decides what they do):

| Keys To Use Within This Block                                 | What It Does Within Your TaskBot's Active Web Page                                                                                                                       |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <kbd>**Tab**</kbd> or <kbd>**Shift**</kbd> <kbd>**Tab**</kbd> | Move focus to the next / previous field, link, or button                                                                                                                 |
| <kbd>**Enter**</kbd>                                          | Submit a form, or activate the focused link or button                                                                                                                    |
| <kbd>**Space**</kbd>                                          | Toggle a focused checkbox or press a focused button, or scroll down a screen when the page itself is focused (<kbd>**Shift**</kbd> <kbd>**Space**</kbd> also scrolls up) |
| <kbd>**Escape**</kbd>                                         | Close a pop-up, modal, dropdown, or autocomplete list on most websites                                                                                                   |
| <kbd>**Home**</kbd>                                           | Jump to the top of the page, or the start of the line when a text field is focused                                                                                       |
| <kbd>**End**</kbd>                                            | Jump to the bottom of the page, or the end of the line when a text field is focused                                                                                      |
| <kbd>**PageUp**</kbd>                                         | Scroll up one screen                                                                                                                                                     |
| <kbd>**PageDown**</kbd>                                       | Scroll down one screen                                                                                                                                                   |
| <kbd>**CMD/Ctrl**</kbd> <kbd>**A**</kbd>                      | Select all the text in the focused field, or page if it's focused                                                                                                        |
| <kbd>**CMD/Ctrl**</kbd> <kbd>**C**</kbd>                      | Copy the current selection to the clipboard                                                                                                                              |
| <kbd>**CMD/Ctrl**</kbd> <kbd>**X**</kbd>                      | Cut the current selection to the clipboard                                                                                                                               |
| <kbd>**CMD/Ctrl**</kbd> <kbd>**V**</kbd>                      | Paste clipboard content into the focused field                                                                                                                           |
| <kbd>**CMD/Ctrl**</kbd> <kbd>**R**</kbd>                      | Refreshes or reloads an active web page. This is the only **browser-level** keyboard shortcut that ZeroWork automatically handles                                        |

{% hint style="info" %}
For moving a page element's text into another field, a ZeroWork variable is often easier than copy and paste: read it with a [Save Web Element](https://docs.zerowork.io/using-zerowork/using-building-blocks/save-web-element) block (save as **Text** to a ZeroWork variable), then paste it with an [Insert Text or Data](https://docs.zerowork.io/using-zerowork/using-building-blocks/insert-text-or-data) block that references that variable, with no clipboard involved.\
\
When the text is only on the clipboard (after a page's own **Copy** button, or a <kbd>**CMD/Ctrl**</kbd> <kbd>**C**</kbd> you send with this block), use a [Save From Clipboard](https://docs.zerowork.io/using-zerowork/using-building-blocks/save-from-clipboard) block to pull it into a variable and reference it in a next block.
{% endhint %}

### Browser-level Keyboard Shortcuts

| To Do This                       | Browser-level Shortcut                                                       | Do This Instead                                                                                                                                                                |
| -------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Find text on the page            | <kbd>**CMD/Ctrl**</kbd> <kbd>**F**</kbd>                                     | [Check Web Element](/using-zerowork/using-building-blocks/check-web-element.md) block or [Save Web Element](/using-zerowork/using-building-blocks/save-web-element.md) block   |
| Go back or forward               | <kbd>**OPTION/Alt**</kbd> <kbd>**LeftArrow**</kbd>/<kbd>**RightArrow**</kbd> | [Go Back or Forward](/using-zerowork/using-building-blocks/go-back-or-forward.md) block                                                                                        |
| Go to a web address in a new tab | <kbd>**CMD/Ctrl**</kbd> <kbd>**N**</kbd>                                     | [Open Link](/using-zerowork/using-building-blocks/open-link.md) block (with [Open in new tab](/using-zerowork/using-building-blocks/open-link.md#open-in-a-new-tab) turned on) |
| Print or save a web page         | <kbd>**CMD/Ctrl**</kbd> <kbd>**P**</kbd>/<kbd>**S**</kbd>                    | [Take Screenshot](/using-zerowork/using-building-blocks/take-screenshot.md) block (visual copy)                                                                                |

More broadly, any shortcut that controls the browser itself or your computer (new windows, zoom, bookmarks, devtools, the address bar, or OS shortcuts) won't reach the browser's active page, so it does nothing here.

{% hint style="success" icon="lightbulb" %}
For a browser-level action with no matching no-code block (for example saving a web page as a PDF), a [Write JavaScript](https://docs.zerowork.io/using-zerowork/using-building-blocks/write-javascript) block running locally gives you access to everything and anything you can do with the full Playwright API.
{% endhint %}

## Block Behavior

**When keys are set** the block sends them to the focused element on the active web page, playing them in the order they were captured, and logs the keys it pressed.

**When a shortcut uses a modifier** the modifier stays held for every key after it until the block ends, so each following key combines with it.

**When the shortcut is&#x20;**<kbd>**CMD/Ctrl**</kbd> <kbd>**R**</kbd> (optionally with <kbd>**Shift**</kbd>) the block reloads the active web page instead of sending the keystroke, and logs that it reloaded the page.

**When the TaskBot's operating system differs from the one the keys were set on** <kbd>**CMD**</kbd> and <kbd>**Ctrl**</kbd> are swapped so the shortcut matches the operating system the TaskBot is running on.

**When no keys are set** the block fails, reporting that no keys were provided.

**When a key can't be pressed** (an unknown or unsupported key) the block fails, reporting that it can't press that key.

## FAQ

1. **Can I copy and paste with&#x20;**<kbd>**CMD/Ctrl**</kbd> <kbd>**C**</kbd>**&#x20;and&#x20;**<kbd>**CMD/Ctrl**</kbd> <kbd>**V**</kbd>**?**\
   Yes. This block sends a real keypress to the page, so the browser's own copy, cut, paste, and select-all all work as you expect: <kbd>**CMD/Ctrl**</kbd> <kbd>**A**</kbd> to select all, <kbd>**CMD/Ctrl**</kbd> <kbd>**C**</kbd> to copy (or <kbd>**CMD/Ctrl**</kbd> <kbd>**X**</kbd> to cut), and <kbd>**CMD/Ctrl**</kbd> <kbd>**V**</kbd> to paste into the focused field.\
   \
   Copying needs something *selected* (often a <kbd>**CMD/Ctrl**</kbd> <kbd>**A**</kbd> in the block right before), and pasting needs the target field *focused*. Once text is on the clipboard, a [Save From Clipboard](https://docs.zerowork.io/using-zerowork/using-building-blocks/save-from-clipboard) block can pull it into a [ZeroWork variable](/using-zerowork/using-variables.md).<br>

   The exception is browser-*window* shortcuts; ones like <kbd>**CMD/Ctrl**</kbd> <kbd>**P**</kbd> (print), <kbd>**CMD/Ctrl**</kbd> <kbd>**F**</kbd> (find or search bar), and <kbd>**CMD/Ctrl**</kbd> <kbd>**S**</kbd> (save page) act on the browser window itself rather than the web page inside that browser window, so this block doesn't open them. <kbd>**CMD/Ctrl**</kbd> <kbd>**R**</kbd> is handled specially by ZeroWork and reloads the page.
2. **Can you give me a keyboard shortcut for a specific web app I'm automating?**\
   [Facebook shortcuts](https://www.webfx.com/blog/social-media/facebook-cheat-sheet-of-keyboard-shortcuts/)\
   [Slack shortcuts](https://slack.com/help/articles/201374536-Slack-keyboard-shortcuts)\
   [Instagram shortcuts](https://greasyfork.org/en/scripts/374589-instagram-keyboard-shortcuts)

## Video Tutorial

{% embed url="<https://youtu.be/gx_qXNK-BDw?si=9oJXqT1hgKIV7cuM>" %}
