---
metadata:
  - name: generator
    content: Diplodoc Platform v5.54.4
alternate:
  - https://yandex.com/dev/games/doc/en/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/hi/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/ko/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/ru/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/tr/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/vi/sdk/defold/events.md
  - https://yandex.com/dev/games/doc/zh/sdk/defold/events.md
  - href: en/sdk/defold/events.md
    type: text/markdown
    title: Markdown version
  - href: ../../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/games/doc/en/llms.txt

# Events

<!-- source: en/_includes/script-common.md -->
<!-- source: en/_includes/script/index-js.md -->

<!-- endsource: en/_includes/script/index-js.md -->

<!-- source: en/_includes/script/requirements-js.md -->

<!-- endsource: en/_includes/script/requirements-js.md -->

<!-- source: en/_includes/script/image-modal-js.md -->

<!-- endsource: en/_includes/script/image-modal-js.md -->
<!-- endsource: en/_includes/script-common.md -->

You can track events that occur when the user presses certain buttons in the game.

Available events and methods to work with them:

```lua showLineNumbers
ysdk = {
  on_event = function (eventName: "EXIT" | "HISTORY_BACK", listener: function): nil,
  dispatch_event = function (eventName: "EXIT" | "HISTORY_BACK", detail: table|nil): nil,
}
```

## HISTORY_BACK {#history-back}

To track clicks on the **Back** button, use the following method:

```lua showLineNumbers
ysdk.on_event("HISTORY_BACK", function (self)
    -- Showing the custom game dialog to the user with the options
    -- to confirm exiting the game, going to the internal settings, store, and so on.
end)
```

{% note alert %}

This event is available only if the game is launched on a TV.

{% endnote %}

## EXIT {#exit}

If the user confirms exiting the game in the custom dialog box that pops up after clicking **Back**, the game must send an exit event. To do this, use the following method:

```lua
ysdk.dispatch_event("EXIT")
```

---



<!-- source: en/_includes/button-git.md -->
<a href="https://github.com/yandex-games-plugins/defold">
  <span class="button">Repository</span>
</a>
<!-- endsource: en/_includes/button-git.md -->
