Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
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。
如果这个输入事件已被取消,则返回 true。
Returns true if this input event is an echo event (only for events of type InputEventKey). An echo event is a repeated key event sent when the user is holding down the key. Any other event type returns false.
Note: The rate at which echo events are sent is typically around 20 events per second (after holding down the key for roughly half a second). However, the key repeat delay/speed can be changed by the user or disabled entirely in the operating system settings. To ensure your project works correctly on all configurations, do not assume the user has a specific key repeat configuration in your project's behavior.
bool is_match(event: InputEvent, exact_match: bool = true) const 🔗
如果指定的 event 与该事件匹配,则返回 true。仅对动作事件有效,即键(InputEventKey)、按钮(InputEventMouseButton 或 InputEventJoypadButton)、轴 InputEventJoypadMotion 或动作(InputEventAction)事件。
如果 exact_match 为 false,它会忽略 InputEventKey 和 InputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。
如果该输入事件被按下,则返回 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 类型的事件相关。