# 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](https://docs.uibakery.io/data/connect-external-js-library#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](https://docs.uibakery.io/concepts/actions/action-basics/use-actions.name.trigger) 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="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FqHasyt8MYt4PZ2GiHwWd%2FCleanShot%202025-03-24%20at%2018.36.32%402x-min.png?alt=media&#x26;token=0e8d2970-da7a-4e32-954c-f659060a5f66" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
