---
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: zh/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/zh/llms.txt

# 事件

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

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

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

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

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

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

您可以跟踪用户在游戏中点击特定按钮时发生的事件。

可用的事件及其处理方法如下：

```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}

要跟踪**返回**按钮的点击行为，请使用以下方法：

```lua showLineNumbers
ysdk.on_event("HISTORY_BACK", function (self)
    -- 向用户显示自定义游戏对话框，其中提供用于
    -- 确认退出游戏、转到内部设置、商店等的选项
end)
```

{% note alert %}

此事件仅在游戏在电视上运行时可用。

{% endnote %}

## EXIT {#exit}

如果用户在点击**返回**之后打开的自定义对话框中确认退出游戏，则游戏应发送退出事件。为此，请使用以下方法：

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

---



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