InputEventKey¶
继承: InputEventWithModifiers < InputEventFromWindow < InputEvent < Resource < RefCounted < Object
表示正在按下或释放的键盘上的键。
描述¶
键盘上按键的输入事件。支持按键按下、按键释放和echo事件。它也可以在Item.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 |
|
属性说明¶
如果true,则在此事件之前已按下该键。echo事件是用户按住按键时发送的重复按键事件。
注意:echo事件的发送速率通常约为每秒20个事件(按住键大约半秒后)。但是,键重复延迟/速度可以由用户更改或在操作系统设置中完全禁用。为了确保您的项目在所有配置上正常工作,不要假设用户在您的项目行为中有特定的键重复配置。
表示当前键盘布局中按键上印刷的本地化标签,该标签对应于Key常量之一或任何有效的Unicode字符。
对于键盘布局中只有一个标签的按键,它等同于keycode。
要获得InputEventKey的人类可读表示,请使用OS.get_keycode_string(event.key_label),其中event是InputEventKey。
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
当前键盘布局中按键上印刷的拉丁标签,该标签对应于Key常量之一。要获得InputEventKey的人类可读表示,请使用OS.get_keycode_string(event.keycode),其中event是InputEventKey。
+-----+ +-----+
| Q | | Q | - "Q" - keycode
| Й | | ض | - "Й" and "ض" - key_label
+-----+ +-----+
KeyLocation location = 0 🔗
void set_location(value: KeyLocation)
KeyLocation get_location()
表示具有左右版本的键的位置,例如Shift或Alt。
代表101/102键美国QWERTY键盘上一个键的物理位置,该键对应于Key中的一个常量。
要获得InputEventKey的人类可读表示,请使用OS.get_keycode_string()和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);
S3.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 🔗
String as_text_location() const 🔗
返回事件的location的String表示形式。如果事件不特定于某个位置,这将是一个空白字符串。
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。