InputEvent
继承: Resource < RefCounted < Object
派生: InputEventAction, InputEventFromWindow, InputEventJoypadButton, InputEventJoypadMotion, InputEventMIDI, InputEventShortcut
输入事件的抽象基类。
描述
各种输入事件的抽象基类。见 Node._input()。
教程
属性
|
方法
accumulate(with_event: InputEvent) |
|
as_text() const |
|
get_action_strength(action: StringName, exact_match: bool = false) const |
|
is_action(action: StringName, exact_match: bool = false) const |
|
is_action_pressed(action: StringName, allow_echo: bool = false, exact_match: bool = false) const |
|
is_action_released(action: StringName, exact_match: bool = false) const |
|
is_action_type() const |
|
is_canceled() const |
|
is_echo() const |
|
is_match(event: InputEvent, exact_match: bool = true) const |
|
is_pressed() const |
|
is_released() const |
|
xformed_by(xform: Transform2D, local_ofs: Vector2 = Vector2(0, 0)) const |
常量
DEVICE_ID_EMULATION = -1 🔗
模拟设备 ID,用于根据触屏事件生成的鼠标输入,或根据鼠标事件生成的触摸输入。可以据此来区分模拟鼠标输入和物理鼠标输入,以及模拟触摸输入和物理触摸输入。
属性说明
事件的设备 ID。
注意:device 在特殊情况下可能为负数,此时表示的不是系统中物理存在的设备。见 DEVICE_ID_EMULATION。
方法说明
bool accumulate(with_event: InputEvent) 🔗
如果给定的输入事件和这个输入事件可以相加,则返回 true(只针对 InputEventMouseMotion 类型的事件)。
给定输入事件的位置、全局位置和速度将被复制。产生的 relative 是两个事件的总和。两个事件的修饰符必须是相同的。
返回事件的 String 字符串表示。
float get_action_strength(action: StringName, exact_match: bool = false) const 🔗
根据给定动作的状态返回 0.0 到 1.0 之间的值。获取 InputEventJoypadMotion 类型事件的值时很有用。
如果 exact_match 为 false,它会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
bool is_action(action: StringName, exact_match: bool = false) const 🔗
如果该输入事件匹配任何类型的预定义动作,则返回 true。
如果 exact_match 为 false,它会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
bool is_action_pressed(action: StringName, allow_echo: bool = false, exact_match: bool = false) const 🔗
如果给定的动作与该事件匹配且正被按下,则返回 true(除非 allow_echo 为 true,否则不是 InputEventKey 事件中的回显事件)。与 InputEventMouseMotion 或 InputEventScreenDrag 类型的事件无关。
如果 exact_match 为 false,则它会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
注意:由于键盘重影,is_action_pressed() 可能会返回 false,即使动作的某个键被按下时也是如此。有关详细信息,请参阅文档中的 《输入示例》。
bool is_action_released(action: StringName, exact_match: bool = false) const 🔗
如果给定的动作与该事件匹配且被释放(即未按下),则返回 true。与 InputEventMouseMotion 或 InputEventScreenDrag 类型的事件无关。
如果 exact_match 为 false,它会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
如果该输入事件的类型可以分配给输入事件则返回 true,这些类型包括:InputEventKey、InputEventMouseButton、InputEventJoypadButton、InputEventJoypadMotion、InputEventAction。其他所有输入事件类型都会返回 false。
如果这个输入事件已被取消,则返回 true。
如果该输入事件是回显事件(仅适用于 InputEventKey 类型的事件),则返回 true。回显事件是用户按住按键时发送的重复按键事件。任何其他事件类型都返回 false。
注意:发送回显事件的速率通常约为每秒 20 个事件(按住按键约半秒钟后)。但是,在操作系统设置中,按键重复延迟/速度可被用户修改或者完全禁用。为确保你的项目在所有配置下都能正常工作,请不要假设用户在项目行为中具有特定的按键重复配置。
bool is_match(event: InputEvent, exact_match: bool = true) const 🔗
如果指定的 event 与该事件匹配,则返回 true。仅对动作事件有效,包括按键事件(InputEventKey)、按钮事件(InputEventMouseButton 或 InputEventJoypadButton)、轴事件 InputEventJoypadMotion、动作事件(InputEventAction)。
如果 exact_match 为 false,检查时会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
注意:该方法只会考虑事件配置(例如键盘按键和游戏手柄轴),不会考虑 is_pressed()、is_released()、is_echo()、is_canceled() 等状态信息。
如果该输入事件是按下事件,则返回 true。与 InputEventMouseMotion 或 InputEventScreenDrag 类型的事件无关。
注意:由于键盘重影,即使按下动作的某个键,is_pressed() 也有可能会返回 false。详见文档中的《输入示例》。
如果该输入事件是松开事件,则返回 true。不适用于类型为 InputEventMouseMotion 和 InputEventScreenDrag 的事件。
InputEvent xformed_by(xform: Transform2D, local_ofs: Vector2 = Vector2(0, 0)) const 🔗
返回给定输入事件的副本,该副本已被 local_ofs 偏移并被 xform 变换。与 InputEventMouseButton、InputEventMouseMotion、InputEventScreenTouch、InputEventScreenDrag、InputEventMagnifyGesture 和 InputEventPanGesture 类型的事件相关。