Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

InputEvent

继承: Resource < RefCounted < Object

派生: InputEventAction, InputEventFromWindow, InputEventJoypadButton, InputEventJoypadMotion, InputEventMIDI, InputEventShortcut

输入事件的抽象基类。

描述

各种输入事件的抽象基类。见 Node._input

教程

属性

int

device

0

方法

bool

accumulate ( InputEvent with_event )

String

as_text ( ) const

float

get_action_strength ( StringName action, bool exact_match=false ) const

bool

is_action ( StringName action, bool exact_match=false ) const

bool

is_action_pressed ( StringName action, bool allow_echo=false, bool exact_match=false ) const

bool

is_action_released ( StringName action, bool exact_match=false ) const

bool

is_action_type ( ) const

bool

is_canceled ( ) const

bool

is_echo ( ) const

bool

is_match ( InputEvent event, bool exact_match=true ) const

bool

is_pressed ( ) const

bool

is_released ( ) const

InputEvent

xformed_by ( Transform2D xform, Vector2 local_ofs=Vector2(0, 0) ) const


属性说明

int device = 0

  • void set_device ( int value )

  • int get_device ( )

该事件的设备 ID。

注意:对于来自触摸屏的模拟鼠标输入,该设备 ID 将总是 -1。可用于区分模拟鼠标输入和物理鼠标输入。


方法说明

bool accumulate ( InputEvent with_event )

如果给定的输入事件和这个输入事件可以相加,则返回 true(只针对 InputEventMouseMotion 类型的事件)。

给定输入事件的位置、全局位置和速度将被复制。产生的 relative 是两个事件的总和。两个事件的修饰符必须是相同的。


String as_text ( ) const

返回事件的 String 字符串表示。


float get_action_strength ( StringName action, bool exact_match=false ) const

根据给定动作的状态返回 0.0 到 1.0 之间的值。获取 InputEventJoypadMotion 类型事件的值时很有用。

如果 exact_matchfalse,它会忽略 InputEventKeyInputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。


bool is_action ( StringName action, bool exact_match=false ) const

如果该输入事件匹配任何类型的预定义动作,则返回 true

如果 exact_matchfalse,它会忽略 InputEventKeyInputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。


bool is_action_pressed ( StringName action, bool allow_echo=false, bool exact_match=false ) const

如果给定的动作正被按下,则返回 true(除非 allow_echotrue,否则不是 InputEventKey 事件中的回显事件)。与 InputEventMouseMotionInputEventScreenDrag 类型的事件无关。

如果 exact_matchfalse,则它会忽略 InputEventKeyInputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。

注意:由于键盘重影,is_action_pressed 可能会返回 false,即使动作的某个键被按下时也是如此。有关详细信息,请参阅文档中的 《输入示例》


bool is_action_released ( StringName action, bool exact_match=false ) const

如果给定的动作被释放(即未按下),则返回 true。与 InputEventMouseMotionInputEventScreenDrag 类型的事件无关。

如果 exact_matchfalse,它会忽略 InputEventKeyInputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。


bool is_action_type ( ) const

如果这个输入事件的类型是可以分配给输入动作的类型,则返回 true


bool is_canceled ( ) const

如果这个输入事件已被取消,则返回 true


bool is_echo ( ) const

如果该输入事件是回显事件(仅适用于 InputEventKey 类型的事件),则返回 true。任何其他事件类型将返回 false


bool is_match ( InputEvent event, bool exact_match=true ) const

如果指定的 event 与该事件匹配,则返回 true。仅对动作事件有效,即键(InputEventKey)、按钮(InputEventMouseButtonInputEventJoypadButton)、轴 InputEventJoypadMotion 或动作(InputEventAction)事件。

如果 exact_matchfalse,它会忽略 InputEventKeyInputEventMouseButton 事件的额外输入修饰键,以及 InputEventJoypadMotion 事件的方向。


bool is_pressed ( ) const

如果该输入事件被按下,则返回 true。与 InputEventMouseMotionInputEventScreenDrag 类型的事件无关。

注意:由于键盘重影,即使按下动作的某个键,is_pressed 也有可能会返回 false。有关详细信息,请参阅文档中的《输入示例》


bool is_released ( ) const

如果该输入事件是回显事件,则返回 true。不适用于类型为 InputEventMouseMotionInputEventScreenDrag 的事件。


InputEvent xformed_by ( Transform2D xform, Vector2 local_ofs=Vector2(0, 0) ) const

返回给定输入事件的副本,该副本已被 local_ofs 偏移并被 xform 变换。与 InputEventMouseButtonInputEventMouseMotionInputEventScreenTouchInputEventScreenDragInputEventMagnifyGesture、和 InputEventPanGesture 类型的事件相关。