InputEvent¶
继承: Resource < RefCounted < Object
派生: InputEventAction, InputEventFromWindow, InputEventJoypadButton, InputEventJoypadMotion, InputEventMIDI, InputEventShortcut
输入事件的抽象基类。
描述¶
所有类型输入事件的抽象基类。参见Item.OnInput()。
属性¶
方法¶
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类型的事件)。
将复制给定输入事件的位置、全局位置和速度。生成的相对是两个事件的总和。两个事件的修饰符必须相同。
返回事件的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(并且不是InputEventKey事件的回显事件,除非allow_echo是true)。与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。
如果此输入事件是回声事件(仅适用于InputEventKey类型的事件),则返回true。回声事件是用户按住按键时发送的重复按键事件。任何其他事件类型都返回false。
注意:echo事件的发送速率通常约为每秒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类型的事件相关。