InputEventKey
繼承: InputEventWithModifiers < InputEventFromWindow < InputEvent < Resource < RefCounted < Object
代表鍵盤上的某個按鍵被按下或鬆開。
說明
鍵盤上的按鍵操作對應的輸入事件。支援按鍵按下、釋放和 echo 事件。還可以在 Node._unhandled_key_input() 收到。
注意:從鍵盤上接收的事件通常設定了所有屬性。事件對應應該只設定 keycode、physical_keycode、unicode 的其中之一。
比較事件時,將按以下優先順序檢查屬性——keycode、physical_keycode、unicode。有一個配對就會認為事件相等。
教學
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
as_text_key_label() const |
|
as_text_keycode() const |
|
as_text_location() const |
|
as_text_physical_keycode() const |
|
get_key_label_with_modifiers() const |
|
get_keycode_with_modifiers() const |
|
屬性說明
If true, the key was already pressed before this event. An echo event is a repeated key event sent when the user is holding down the key.
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.
Represents the localized label printed on the key in the current keyboard layout, which corresponds to one of the Key constants or any valid Unicode character.
For keyboard layouts with a single label on the key, it is equivalent to keycode.
To get a human-readable representation of the InputEventKey, use OS.get_keycode_string(event.key_label) where event is the InputEventKey.
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
Latin label printed on the key in the current keyboard layout, which corresponds to one of the Key constants.
To get a human-readable representation of the InputEventKey, use OS.get_keycode_string(event.keycode) where event is the InputEventKey.
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
KeyLocation location = 0 🔗
void set_location(value: KeyLocation)
KeyLocation get_location()
Represents the location of a key which has both left and right versions, such as Shift or Alt.
Represents the physical location of a key on the 101/102-key US QWERTY keyboard, which corresponds to one of the Key constants.
To get a human-readable representation of the InputEventKey, use OS.get_keycode_string() in combination with DisplayServer.keyboard_get_keycode_from_physical():
func _input(event):
if event is InputEventKey:
var keycode = DisplayServer.keyboard_get_keycode_from_physical(event.physical_keycode)
print(OS.get_keycode_string(keycode))
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey inputEventKey)
{
var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode);
GD.Print(OS.GetKeycodeString(keycode));
}
}
如果為 true,按鍵的狀態是被按下。如果為 false,該鍵的狀態被釋放。
按鍵 Unicode 字元程式碼(當相關時),由修飾鍵移動。除非 IME 輸入模式處於活動狀態,否則複合字元和複雜文字的 Unicode 字元程式碼可能不可用。有關詳細資訊,請參閱 Window.set_ime_active()。
方法說明
String as_text_key_label() const 🔗
返回該事件 key_label 及修飾鍵的 String 字串表示。
String as_text_keycode() const 🔗
返回該事件 keycode 及修飾鍵的 String 字串表示。
String as_text_location() const 🔗
Returns a String representation of the event's location. This will be a blank string if the event is not specific to a location.
String as_text_physical_keycode() const 🔗
返回該事件 physical_keycode 及修飾鍵的 String 字串表示。
Key get_key_label_with_modifiers() const 🔗
返回與修飾鍵,例如 Shift 或 Alt 組合的當地語系化鍵標籤。另見 InputEventWithModifiers。
要獲得帶有修飾鍵的 InputEventKey 的人類可讀表示,請使用 OS.get_keycode_string(event.get_key_label_with_modifiers()),其中 event 是 InputEventKey。
Key get_keycode_with_modifiers() const 🔗
返回與 Shift 或 Alt 等修飾鍵組合的拉丁鍵碼。另見 InputEventWithModifiers。
要獲得帶有修飾鍵的 InputEventKey 的人類可讀表示,請使用 OS.get_keycode_string(event.get_keycode_with_modifiers()),其中 event 是 InputEventKey。
Key get_physical_keycode_with_modifiers() const 🔗
返回與諸如 Shift 或 Alt 的修飾鍵組合的物理鍵碼。另請參閱 InputEventWithModifiers。
要獲得帶有修飾符的 InputEventKey 的人類可讀表示,請使用 OS.get_keycode_string(event.get_physical_keycode_with_modifiers()),其中 event 是 InputEventKey。