:github_url: hide .. _class_InputMap: InputMap ======== **继承:** :ref:`Object` 管理所有 :ref:`InputEventAction` 的单例。 .. rst-class:: classref-introduction-group 描述 ---- 管理所有的 :ref:`InputEventAction`\ ,可以通过项目设置菜单\ **项目 > 项目设置 > 输入映射**\ 或在代码中用 :ref:`add_action()` 和 :ref:`action_add_event()` 创建/修改。请参阅 :ref:`Node._input()`\ 。 .. rst-class:: classref-introduction-group 教程 ---- - `使用 InputEvent:InputMap <../tutorials/inputs/inputevent.html#inputmap>`__ .. rst-class:: classref-reftable-group 方法 ---- .. table:: :widths: auto +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`action_add_event`\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`action_erase_event`\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`action_erase_events`\ (\ action\: :ref:`StringName`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`float` | :ref:`action_get_deadzone`\ (\ action\: :ref:`StringName`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array`\[:ref:`InputEvent`\] | :ref:`action_get_events`\ (\ action\: :ref:`StringName`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`action_has_event`\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`action_set_deadzone`\ (\ action\: :ref:`StringName`, deadzone\: :ref:`float`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`add_action`\ (\ action\: :ref:`StringName`, deadzone\: :ref:`float` = 0.2\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`erase_action`\ (\ action\: :ref:`StringName`\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`event_is_action`\ (\ event\: :ref:`InputEvent`, action\: :ref:`StringName`, exact_match\: :ref:`bool` = false\ ) |const| | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`String` | :ref:`get_action_description`\ (\ action\: :ref:`StringName`\ ) |const| | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Array`\[:ref:`StringName`\] | :ref:`get_actions`\ (\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`has_action`\ (\ action\: :ref:`StringName`\ ) |const| | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`load_from_project_settings`\ (\ ) | +------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group 方法说明 -------- .. _class_InputMap_method_action_add_event: .. rst-class:: classref-method |void| **action_add_event**\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) :ref:`🔗` 给某个动作添加一个 :ref:`InputEvent`\ 。这个 :ref:`InputEvent` 将触发这个动作。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_erase_event: .. rst-class:: classref-method |void| **action_erase_event**\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) :ref:`🔗` 从某个动作中删除一个 :ref:`InputEvent`\ 。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_erase_events: .. rst-class:: classref-method |void| **action_erase_events**\ (\ action\: :ref:`StringName`\ ) :ref:`🔗` 从某个动作中删除所有事件。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_get_deadzone: .. rst-class:: classref-method :ref:`float` **action_get_deadzone**\ (\ action\: :ref:`StringName`\ ) :ref:`🔗` 返回该操作的死区值。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_get_events: .. rst-class:: classref-method :ref:`Array`\[:ref:`InputEvent`\] **action_get_events**\ (\ action\: :ref:`StringName`\ ) :ref:`🔗` 返回与给定动作关联的 :ref:`InputEvent` 的数组。 \ **注意:**\ 在编辑器中使用时(例如在工具脚本或 :ref:`EditorPlugin` 中使用),这个方法返回的是编辑器动作对应的事件。如果你想要在编辑器中访问你的项目的输入绑定,请读取 :ref:`ProjectSettings` 的 ``input/*`` 设置。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_has_event: .. rst-class:: classref-method :ref:`bool` **action_has_event**\ (\ action\: :ref:`StringName`, event\: :ref:`InputEvent`\ ) :ref:`🔗` 如果该动作有给定的 :ref:`InputEvent` 与之相关,则返回 ``true``\ 。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_action_set_deadzone: .. rst-class:: classref-method |void| **action_set_deadzone**\ (\ action\: :ref:`StringName`, deadzone\: :ref:`float`\ ) :ref:`🔗` 为该动作设置死区值。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_add_action: .. rst-class:: classref-method |void| **add_action**\ (\ action\: :ref:`StringName`, deadzone\: :ref:`float` = 0.2\ ) :ref:`🔗` 在 **InputMap** 上添加空的动作,死区可使用 ``deadzone`` 配置。 然后可以用 :ref:`action_add_event()` 给这个动作添加 :ref:`InputEvent`\ 。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_erase_action: .. rst-class:: classref-method |void| **erase_action**\ (\ action\: :ref:`StringName`\ ) :ref:`🔗` 从 **InputMap** 中删除一个动作。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_event_is_action: .. rst-class:: classref-method :ref:`bool` **event_is_action**\ (\ event\: :ref:`InputEvent`, action\: :ref:`StringName`, exact_match\: :ref:`bool` = false\ ) |const| :ref:`🔗` 如果给定的事件是现有动作的一部分,返回 ``true``\ 。如果给定的 :ref:`InputEvent` 没有被按下,这个方法会忽略键盘(为了正确地检测释放)。如果你不想要这种行为,请参阅 :ref:`action_has_event()`\ 。 如果 ``exact_match`` 是 ``false``\ ,它会忽略 :ref:`InputEventKey` 和 :ref:`InputEventMouseButton` 事件的额外输入修饰键,以及 :ref:`InputEventJoypadMotion` 事件的方向。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_get_action_description: .. rst-class:: classref-method :ref:`String` **get_action_description**\ (\ action\: :ref:`StringName`\ ) |const| :ref:`🔗` 返回给定动作的人类可读描述。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_get_actions: .. rst-class:: classref-method :ref:`Array`\[:ref:`StringName`\] **get_actions**\ (\ ) :ref:`🔗` 返回 **InputMap** 中所有动作的数组。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_has_action: .. rst-class:: classref-method :ref:`bool` **has_action**\ (\ action\: :ref:`StringName`\ ) |const| :ref:`🔗` 如果 **InputMap** 有一个给定名称的注册动作,返回 ``true``\ 。 .. rst-class:: classref-item-separator ---- .. _class_InputMap_method_load_from_project_settings: .. rst-class:: classref-method |void| **load_from_project_settings**\ (\ ) :ref:`🔗` 清除 **InputMap** 中的所有 :ref:`InputEventAction`\ ,并从 :ref:`ProjectSettings` 项目设置中重新加载它。 .. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)` .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)` .. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)` .. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)` .. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)` .. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)` .. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)` .. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)` .. |void| replace:: :abbr:`void (无返回值。)`