跳转至

GFInputDetector

API Reference / Standard / 类索引

  • 路径:addons/gf/standard/input/rebinding/gf_input_detector.gd
  • 模块:Standard
  • 继承:Node
  • API:public
  • 类别:运行时服务 (runtime_service)
  • 首次版本:3.17.0

检测下一次输入事件的辅助节点。 可用于项目自己的改键界面。检测结果只返回 Godot InputEvent,冲突处理由项目层决定。

成员概览

类型 名称 签名
信号 detection_started signal detection_started
信号 input_detected signal input_detected(input_event: InputEvent)
枚举 DeviceType enum DeviceType
枚举 DetectionState enum DetectionState
属性 ignore_echo var ignore_echo: bool = true
属性 minimum_axis_amplitude var minimum_axis_amplitude: float = 0.25
属性 countdown_seconds var countdown_seconds: float = 0.0
属性 timeout_seconds var timeout_seconds: float = 0.0
属性 abort_events var abort_events: Array[InputEvent] = []
属性 wait_for_clear_before_detection var wait_for_clear_before_detection: bool = true
属性 wait_for_clear_after_detection var wait_for_clear_after_detection: bool = false
方法 begin_detection func begin_detection(allowed_device_types: Array[int] = []) -> void:
方法 begin_detection_for_value_type func begin_detection_for_value_type( value_type: GFInputAction.ValueType, allowed_device_types: Array[int] = [] ) -> void:
方法 begin_detection_for_action func begin_detection_for_action( action: GFInputAction, allowed_device_types: Array[int] = [] ) -> void:
方法 detect_bool func detect_bool(allowed_device_types: Array[int] = []) -> void:
方法 detect_axis_1d func detect_axis_1d(allowed_device_types: Array[int] = []) -> void:
方法 detect_axis_2d func detect_axis_2d(allowed_device_types: Array[int] = []) -> void:
方法 detect_axis_3d func detect_axis_3d(allowed_device_types: Array[int] = []) -> void:
方法 get_countdown_remaining func get_countdown_remaining() -> float:
方法 get_detection_state func get_detection_state() -> DetectionState:
方法 is_accepting_input func is_accepting_input() -> bool:
方法 cancel_detection func cancel_detection() -> void:
方法 is_detecting func is_detecting() -> bool:

信号

detection_started

  • API:public
signal detection_started

开始检测时发出。

input_detected

  • API:public
signal input_detected(input_event: InputEvent)

检测结束时发出。input_event 为 null 表示取消或超时。

参数:

名称 说明
input_event 检测到的输入事件;取消或超时时为 null。

枚举

DeviceType

  • API:public
enum DeviceType { ## 键盘输入。 KEYBOARD, ## 鼠标输入。 MOUSE, ## 手柄按钮或轴输入。 JOYPAD, ## 触屏输入。 TOUCH, }

设备过滤类型。

DetectionState

  • API:public
enum DetectionState { ## 未检测。 IDLE, ## 倒计时中。 COUNTDOWN, ## 等待取消输入释放。 PRE_CLEAR, ## 正在接收候选输入。 DETECTING, ## 等待检测到的输入释放。 POST_CLEAR, }

检测阶段。

属性

ignore_echo

  • API:public
var ignore_echo: bool = true

是否忽略键盘 echo 事件。

minimum_axis_amplitude

  • API:public
var minimum_axis_amplitude: float = 0.25

轴输入检测阈值。

countdown_seconds

  • API:public
var countdown_seconds: float = 0.0

正式接收输入前的倒计时。可用于改键界面避开确认按钮本身。

timeout_seconds

  • API:public
var timeout_seconds: float = 0.0

检测超时时间。小于等于 0 表示不超时。

abort_events

  • API:public
var abort_events: Array[InputEvent] = []

取消检测的输入事件列表。

结构:

  • abort_events: Array[InputEvent] used to cancel detection or wait for release before accepting input.

wait_for_clear_before_detection

  • API:public
var wait_for_clear_before_detection: bool = true

开始正式检测前,是否等待 abort_events 中仍按住的输入释放。

wait_for_clear_after_detection

  • API:public
var wait_for_clear_after_detection: bool = false

检测到输入后,是否等待该输入释放再发出 input_detected。

方法

begin_detection

  • API:public
func begin_detection(allowed_device_types: Array[int] = []) -> void:

开始检测下一次输入。

参数:

名称 说明
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

begin_detection_for_value_type

  • API:public
func begin_detection_for_value_type( value_type: GFInputAction.ValueType, allowed_device_types: Array[int] = [] ) -> void:

按动作值类型开始检测下一次输入。

参数:

名称 说明
value_type 期望的动作值类型。
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

begin_detection_for_action

  • API:public
func begin_detection_for_action( action: GFInputAction, allowed_device_types: Array[int] = [] ) -> void:

按动作资源开始检测下一次输入。

参数:

名称 说明
action 输入动作资源。
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

detect_bool

  • API:public
func detect_bool(allowed_device_types: Array[int] = []) -> void:

开始检测布尔输入。

参数:

名称 说明
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

detect_axis_1d

  • API:public
func detect_axis_1d(allowed_device_types: Array[int] = []) -> void:

开始检测一维轴输入。

参数:

名称 说明
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

detect_axis_2d

  • API:public
func detect_axis_2d(allowed_device_types: Array[int] = []) -> void:

开始检测二维轴输入。

参数:

名称 说明
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

detect_axis_3d

  • API:public
func detect_axis_3d(allowed_device_types: Array[int] = []) -> void:

开始检测三维轴输入。

参数:

名称 说明
allowed_device_types 允许的设备类型。空数组表示不限制。

结构:

  • allowed_device_types: Array[int],包含 DeviceType 枚举值;为空表示不过滤设备。

get_countdown_remaining

  • API:public
func get_countdown_remaining() -> float:

获取正式接收输入前剩余的倒计时秒数。

返回:剩余秒数。

get_detection_state

  • API:public
func get_detection_state() -> DetectionState:

获取当前检测阶段。

返回:检测阶段。

is_accepting_input

  • API:public
func is_accepting_input() -> bool:

是否已经结束倒计时并正在接收候选输入。

返回:是否可接收输入。

cancel_detection

  • API:public
func cancel_detection() -> void:

取消检测。

is_detecting

  • API:public
func is_detecting() -> bool:

检查当前是否正在检测。

返回:是否正在检测。