跳转至

GFInputEventIdentity

API Reference / Standard / 类索引

  • 路径:addons/gf/standard/input/common/gf_input_event_identity.gd
  • 模块:Standard
  • 继承:RefCounted
  • API:public
  • 类别:值对象 (value_object)
  • 首次版本:8.0.0

输入事件的稳定语义身份。 将 Godot InputEvent 归一为框架可复用的显示键、冲突键与图标候选键。 它不读取 InputMap,不规定项目 action 命名,也不绑定具体图标资源。

成员概览

类型 名称 签名
常量 KIND_NONE const KIND_NONE: StringName = &""
常量 KIND_ACTION const KIND_ACTION: StringName = &"action"
常量 KIND_KEY const KIND_KEY: StringName = &"key"
常量 KIND_MOUSE_BUTTON const KIND_MOUSE_BUTTON: StringName = &"mouse_button"
常量 KIND_JOY_BUTTON const KIND_JOY_BUTTON: StringName = &"joy_button"
常量 KIND_JOY_AXIS const KIND_JOY_AXIS: StringName = &"joy_axis"
常量 KIND_TOUCH const KIND_TOUCH: StringName = &"touch"
常量 KIND_SCREEN_DRAG const KIND_SCREEN_DRAG: StringName = &"screen_drag"
常量 KIND_UNKNOWN const KIND_UNKNOWN: StringName = &"unknown"
属性 kind var kind: StringName = KIND_NONE
属性 primary_key var primary_key: String = ""
属性 display_key var display_key: String = ""
属性 conflict_key var conflict_key: String = ""
属性 icon_key var icon_key: StringName = &""
属性 device_id var device_id: int = -1
属性 axis_sign var axis_sign: int = 0
属性 metadata var metadata: Dictionary = {}
方法 from_event static func from_event(input_event: InputEvent, options: Dictionary = {}) -> GFInputEventIdentity:
方法 get_icon_candidates static func get_icon_candidates(input_event: InputEvent, options: Dictionary = {}) -> PackedStringArray:
方法 is_empty func is_empty() -> bool:
方法 get_signature func get_signature(include_device: bool = false) -> String:
方法 to_dictionary func to_dictionary(json_compatible: bool = true) -> Dictionary:
方法 from_dictionary static func from_dictionary(data: Dictionary) -> GFInputEventIdentity:

常量

KIND_NONE

  • API:public
  • 首次版本:8.0.0
const KIND_NONE: StringName = &""

未识别或空输入事件。

KIND_ACTION

  • API:public
  • 首次版本:8.0.0
const KIND_ACTION: StringName = &"action"

Godot InputEventAction。

KIND_KEY

  • API:public
  • 首次版本:8.0.0
const KIND_KEY: StringName = &"key"

键盘按键事件。

KIND_MOUSE_BUTTON

  • API:public
  • 首次版本:8.0.0
const KIND_MOUSE_BUTTON: StringName = &"mouse_button"

鼠标按钮事件。

KIND_JOY_BUTTON

  • API:public
  • 首次版本:8.0.0
const KIND_JOY_BUTTON: StringName = &"joy_button"

手柄按钮事件。

KIND_JOY_AXIS

  • API:public
  • 首次版本:8.0.0
const KIND_JOY_AXIS: StringName = &"joy_axis"

手柄轴事件。

KIND_TOUCH

  • API:public
  • 首次版本:8.0.0
const KIND_TOUCH: StringName = &"touch"

触屏按下事件。

KIND_SCREEN_DRAG

  • API:public
  • 首次版本:8.0.0
const KIND_SCREEN_DRAG: StringName = &"screen_drag"

触屏拖动事件。

KIND_UNKNOWN

  • API:public
  • 首次版本:8.0.0
const KIND_UNKNOWN: StringName = &"unknown"

未专门建模的其他 InputEvent。

属性

kind

  • API:public
  • 首次版本:8.0.0
var kind: StringName = KIND_NONE

输入事件类别。

primary_key

  • API:public
  • 首次版本:8.0.0
var primary_key: String = ""

主身份键。用于日志、报告和调试展示中的稳定归类。

display_key

  • API:public
  • 首次版本:8.0.0
var display_key: String = ""

显示键。用于 UI 或文档层决定如何进一步本地化。

conflict_key

  • API:public
  • 首次版本:8.0.0
var conflict_key: String = ""

冲突键。默认不包含设备 ID,设备匹配应使用 get_signature()。

icon_key

  • API:public
  • 首次版本:8.0.0
var icon_key: StringName = &""

首选图标键。没有稳定图标语义时为空。

device_id

  • API:public
  • 首次版本:8.0.0
var device_id: int = -1

输入事件携带的 Godot device ID。

axis_sign

  • API:public
  • 首次版本:8.0.0
var axis_sign: int = 0

轴方向。正向为 1,负向为 -1,未知或不适用为 0。

metadata

  • API:public
  • 首次版本:8.0.0
var metadata: Dictionary = {}

附加元数据。

结构:

  • metadata: Dictionary,包含事件类型相关的纯数据字段。

方法

from_event

  • API:public
  • 首次版本:8.0.0
static func from_event(input_event: InputEvent, options: Dictionary = {}) -> GFInputEventIdentity:

从输入事件构建稳定身份。

参数:

名称 说明
input_event 输入事件。
options 归一化选项。

返回:输入事件身份;空事件返回 kind 为空的身份。

结构:

  • options: Dictionary,可包含 include_key_modifiers、include_key_modifier_combo、match_touch_index 和 joy_axis_sign。

get_icon_candidates

  • API:public
  • 首次版本:8.0.0
static func get_icon_candidates(input_event: InputEvent, options: Dictionary = {}) -> PackedStringArray:

获取输入事件可能使用的图标键。

参数:

名称 说明
input_event 输入事件。
options 归一化选项。

返回:图标键列表,按优先级排序。

结构:

  • options: Dictionary,可包含 include_key_modifier_combo、match_touch_index 和 joy_axis_sign。

is_empty

  • API:public
  • 首次版本:8.0.0
func is_empty() -> bool:

判断身份是否为空。

返回:空身份返回 true。

get_signature

  • API:public
  • 首次版本:8.0.0
func get_signature(include_device: bool = false) -> String:

获取冲突签名。

参数:

名称 说明
include_device 是否把 device_id 纳入签名。

返回:稳定冲突签名;空身份返回空字符串。

to_dictionary

  • API:public
  • 首次版本:8.0.0
func to_dictionary(json_compatible: bool = true) -> Dictionary:

转换为字典。

参数:

名称 说明
json_compatible 是否把 metadata 转换为 JSON 兼容值。

返回:身份字典。

结构:

  • return: Dictionary with kind, primary_key, display_key, conflict_key, icon_key, device_id, axis_sign, and metadata fields.

from_dictionary

  • API:public
  • 首次版本:8.0.0
static func from_dictionary(data: Dictionary) -> GFInputEventIdentity:

从字典恢复输入事件身份。

参数:

名称 说明
data 身份字典。

返回:输入事件身份。

结构:

  • data: Dictionary produced by to_dictionary(), or a compatible dictionary with the same fields.