Class InputEventKey
- Namespace
- Godot
- Assembly
- GodotSharp.dll
An input event for keys on a keyboard. Supports key presses, key releases and Echo events. It can also be received in _UnhandledKeyInput(InputEvent).
Note: Events received from the keyboard usually have all properties set. Event mappings should have only one of the Keycode, PhysicalKeycode or Unicode set.
When events are compared, properties are checked in the following priority - Keycode, PhysicalKeycode and Unicode. Events with the first matching value will be considered equal.
public class InputEventKey : InputEventWithModifiers, IDisposable
- Inheritance
-
InputEventKey
- Implements
- Inherited Members
Constructors
InputEventKey()
public InputEventKey()
Properties
Echo
If true
, the key was already pressed before this event. It means the user is holding the key down.
public bool Echo { get; set; }
Property Value
KeyLabel
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
+-----+ +-----+
public Key KeyLabel { get; set; }
Property Value
Keycode
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
+-----+ +-----+
public Key Keycode { get; set; }
Property Value
PhysicalKeycode
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 GetKeycodeString(Key) in combination with KeyboardGetKeycodeFromPhysical(Key):
public override void _Input(InputEvent @event)
{
if (@event is InputEventKey inputEventKey)
{
var keycode = DisplayServer.KeyboardGetKeycodeFromPhysical(inputEventKey.PhysicalKeycode);
GD.Print(OS.GetKeycodeString(keycode));
}
}
public Key PhysicalKeycode { get; set; }
Property Value
Pressed
If true
, the key's state is pressed. If false
, the key's state is released.
public bool Pressed { get; set; }
Property Value
Unicode
The key Unicode character code (when relevant), shifted by modifier keys. Unicode character codes for composite characters and complex scripts may not be available unless IME input mode is active. See SetImeActive(bool) for more information.
public long Unicode { get; set; }
Property Value
Methods
AsTextKeyLabel()
public string AsTextKeyLabel()
Returns
AsTextKeycode()
public string AsTextKeycode()
Returns
AsTextPhysicalKeycode()
Returns a string representation of the event's PhysicalKeycode and modifiers.
public string AsTextPhysicalKeycode()
Returns
GetKeyLabelWithModifiers()
Returns the localized key label combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.
To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_key_label_with_modifiers())
where event
is the InputEventKey.
public Key GetKeyLabelWithModifiers()
Returns
GetKeycodeWithModifiers()
Returns the Latin keycode combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.
To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_keycode_with_modifiers())
where event
is the InputEventKey.
public Key GetKeycodeWithModifiers()
Returns
GetPhysicalKeycodeWithModifiers()
Returns the physical keycode combined with modifier keys such as Shift or Alt. See also InputEventWithModifiers.
To get a human-readable representation of the InputEventKey with modifiers, use OS.get_keycode_string(event.get_physical_keycode_with_modifiers())
where event
is the InputEventKey.
public Key GetPhysicalKeycodeWithModifiers()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.