> For the complete documentation index, see [llms.txt](https://docs.uibakery.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.uibakery.io/how-tos/custom-code/implementing-custom-app-hotkeys.md).

# Implementing custom app hotkeys

In UI Bakery, you can implement custom hotkeys for your application if necessary. You can do this using UI Bakery actions and the [hotkeys-js](https://github.com/jaywcjlove/hotkeys-js) library. Check it out:point\_down:

1. Start by connecting the [hotkeys-js](https://github.com/jaywcjlove/hotkeys-js) library - navigate to the **Custom code** tab and add the following script tag:

```html
<script src="https://cdn.jsdelivr.net/npm/hotkeys-js@3.10.1/dist/hotkeys.min.js"></script>
```

{% hint style="info" %}
You can find more information on connecting and using external JavaScript libraries [here](/how-tos/data/connect-external-js-library.md#using-external-third-party-js-library).
{% endhint %}

2. Next, set up a **global** action to define the hotkeys:
   1. Click on the app area or select your current page in the *Pages* tab to access the **Settings** of the current page (right side panel).
   2. For the **On App Load/On Page Load** trigger, click *Create action.*
   3. Add a **JavaScript Code** action and define your hotkeys and action calls in the code, for example:

```javascript
hotkeys('E', function(event, handler){
  event.preventDefault();
  alert('E');
});
```

3. Now, test the hotkey - run the action, focus the app area, and press the **E keyboard key**.\
   This should open the browser alert.

{% hint style="warning" %}
The hotkeys will only work when the **app area is focused**. If the hotkeys don't work, try clicking on the app area to focus it.
{% endhint %}

You can also refer to [hotkeys-js documentation](https://github.com/jaywcjlove/hotkeys-js#defining-shortcuts) for additional information on defining hotkeys.

{% @arcade/embed flowId="Gao49XFZjvZEUtGSzENL" url="<https://app.arcade.software/share/Gao49XFZjvZEUtGSzENL>" %}

***

You can also further extend the code above and define a **hotkey-action pairing** assuming that you've already configured the actions that you'd like to trigger with the hotkeys, for example:

```javascript
hotkeys('ctrl+a,ctrl+b,r,f', async function (event, handler){
  switch (handler.key) {
    case 'ctrl+a':
      await actions.hotkeyA.trigger();
      break;
    case 'ctrl+b':
      await actions.hotkeyB.trigger();
      break;
    case 'r': 
      alert('you pressed r!');
      break;
    case 'f': 
      alert('you pressed f!');
      break;
  }
});
```

{% hint style="info" %}
Notice how this example utilizes the ability to call UI Bakery actions using *async/await syntax* with `await actions.hotkeyA.trigger();`. Refer to [this article](/concepts/actions/action-basics/use-actions.name.trigger.md) for more details on calling actions from code.
{% endhint %}

After defining and setting everything up, you need to reload the app to test the final setup. The hotkeys action will be executed upon app/page load, defining the hotkeys to activate the app's actions.

<figure><img src="/files/PMGkcFtjhoiyWyJKcN5a" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.uibakery.io/how-tos/custom-code/implementing-custom-app-hotkeys.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
