# ShortcutManager

The `ShortcutManager` API allows developers to register keyboard shortcuts for specified actions using JS or TS.&#x20;

{% hint style="info" %}
**Version compatibility**

* `ShortcutManager` was introduced in version **4.58.0** of the JourneyApps Runtime.
* Keyboard shortcuts are only supported on Desktop.
  {% endhint %}

{% hint style="info" %}
This document describes registering and unregistering keyboard shortcuts via JS/TS. For the `shortcut` XML components see [these docs](https://docs.journeyapps.com/reference/build/ui-components/all-ui-components/shortcut).
{% endhint %}

### Basic Example

{% code title="main.js" %}

```javascript
ShortcutManager.registerShortcut('CTRL+SHIFT+K', function() {
    notification.info('CTRL+SHIFT+K was pressed');
});
```

{% endcode %}

### Methods

#### registerShortcut

<pre class="language-javascript"><code class="lang-javascript"><strong>ShortcutManager.registerShortcut(keys, callback)
</strong></code></pre>

Allows developers to register a new keyboard shortcut, and specify the corresponding action (via a callback function). The key combination (`keys` parameter) for a shortcut is the shortcut's unique identifier, hence if duplicate shortcuts are registered, only the last registered callback action will execute.

| Parameter  | Type     | Example                                        |
| ---------- | -------- | ---------------------------------------------- |
| `keys`     | `string` | "CTRL+K"                                       |
| `callback` | Function | See the [basic example](#basic-example) above. |

{% hint style="info" %}
**Registering shortcuts over multiple views**

To have a keyboard shortcut be available globally (i.e. in multiple views of your app), the shortcut should get registered in your app's SharedJS (in a JavaScript app) or App Modules (in a TypeScript app).
{% endhint %}

{% hint style="warning" %}
**Reserved keys**

The following keys are reserved and hence cannot be used as `keys`:

* CTRL+Z
* CTRL+SHIFT+Z
* CTRL+Y
* CTRL+C
* CTRL+V
* CTRL+R
* ESC
* ENTER
* BACKSPACE
* DELETE
  {% endhint %}

#### unregisterShortcut

<pre class="language-javascript"><code class="lang-javascript"><strong>ShortcutManager.unregisterShortcut(keys)
</strong></code></pre>

Allows developers to unregister a previously registered keyboard shortcut.

| Parameter | Type     | Example  |
| --------- | -------- | -------- |
| `keys`    | `string` | "CTRL+K" |
