# Global Shortcuts

## Methods

### <mark style="color:purple;">Register Shortcut</mark>

Sets the app to listen for the specific keys to be pressed, even if the app is not in focus.

{% hint style="danger" %}
When the accelerator is already taken by other applications, this call will silently fail. This behavior is intended by operating systems, since they don't want applications to fight for global shortcuts.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.shortcuts.register({ arguments })
```

**Arguments**

* `accelerator` <mark style="color:green;">String</mark>\
  The specific trigger keys. [Check here](https://www.electronjs.org/docs/latest/tutorial/keyboard-shortcuts) for available keys.
* `id` <mark style="color:green;">String</mark> (Optional)\
  The ID of the shortcut. If none is given, one will be randomly generated.

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
* `id` <mark style="color:green;">String</mark>\
  The ID of the shortcut. If none is given, one will be randomly generated.

**Example**

{% code overflow="wrap" %}

```javascript
const result = await window.deskifier.shortcuts.register({
    accelerator: 'CommandOrControl+Y',
    id: 'abc123'
});

console.log(result.id);  // abc123
```

{% endcode %}
{% endtab %}
{% endtabs %}

***

### <mark style="color:purple;">Unregister Shortcut</mark>

Unregisters the shortcut.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.shortcuts.unregister({ arguments })
```

**Arguments**

* `id` <mark style="color:green;">String</mark> (Required)

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

### <mark style="color:purple;">Unregister All Shortcuts</mark>

Unregisters all shortcuts.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.shortcuts.unregisterAll()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
  {% endtab %}
  {% endtabs %}

***

## Properties

### <mark style="color:purple;">Get Shortcuts</mark>

Retrieves all of the registered shortcuts by the application.

{% hint style="warning" %}
If a registered accelerator is already taken by other applications, this call will still return it as registered. This behavior is intended by operating systems, since they don't want applications to fight for global shortcuts.
{% endhint %}

{% tabs %}
{% tab title="JavaScript" %}

```javascript
await window.deskifier.shortcuts.getAll()
```

**Returns**

* `success` <mark style="color:green;">Boolean</mark>\
  If the action was successful.
* `message` <mark style="color:green;">String</mark>\
  Additional confirmation, or error details if action was unsuccessful.
* `shortcuts` <mark style="color:blue;">Array of</mark> Objects, each with:
  * `accelerator` <mark style="color:green;">String</mark>
  * `id` <mark style="color:green;">String</mark>
    {% endtab %}
    {% endtabs %}

***

## Events

### <mark style="color:purple;">Shortcut Triggered</mark>

Fires when a shortcut is used.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.deskifier.shortcuts.onTriggered((data) => { })
```

**Arguments**

* `accelerator` <mark style="color:green;">String</mark>
* `id` <mark style="color:green;">String</mark>
  {% endtab %}
  {% endtabs %}


---

# 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://deskifier.gitbook.io/deskifier/global-shortcuts.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.
