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,用於根據觸屏事件生成的滑鼠輸入,或根據滑鼠事件生成的觸摸輸入。可以據此來區分模擬滑鼠輸入和物理滑鼠輸入,以及模擬觸摸輸入和物理觸摸輸入。
DEVICE_ID_KEYBOARD = 16 🔗
用於鍵盤輸入的裝置 ID。這可用於區分鍵盤輸入事件和遊戲控制器輸入事件。
DEVICE_ID_MOUSE = 32 🔗
用於滑鼠輸入的裝置 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 🔗
Returns a value between 0.0 and 1.0 depending on the given action's state. Useful for getting the value of events of type InputEventJoypadMotion.
If exact_match is false, it ignores additional input modifiers for InputEventKey and InputEventMouseButton events, and the direction for InputEventJoypadMotion events.
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 型別的事件相關。