Class KeyboardEventBase<T>
This is the base class for keyboard events.
Inherited Members
Namespace: UnityEngine.UIElements
Syntax
public abstract class KeyboardEventBase<T> : EventBase<T>, IKeyboardEvent where T : KeyboardEventBase<T>, new()
Type Parameters
Name | Description |
---|---|
T |
Remarks
The typical keyboard event loop is as follows:
- When a key is pressed, a KeyDownEvent is sent.
- If the key is held down for a duration determined by the OS, another KeyDownEvent with the same data is sent. While the key is held down, the event is sent repeatedly at a frequency determined by the OS.
- When the key is released, a KeyUpEvent is sent.
By default, keyboard events trickle down and bubble up. They are cancellable.
Constructors
KeyboardEventBase()
Declaration
protected KeyboardEventBase()
Properties
actionKey
Gets a boolean value that indicates whether the platform-specific action key is pressed. True means the action key is pressed. False means it isn't.
Declaration
public bool actionKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
Remarks
The platform-specific action key is Cmd on macOS, and Ctrl on all other platforms.
altKey
Gets a boolean value that indicates whether the Alt key is pressed. True means the Alt key is pressed. False means it isn't.
Declaration
public bool altKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
character
Gets the character entered.
Declaration
public char character { get; protected set; }
Property Value
Type | Description |
---|---|
Char |
Implements
Remarks
This is the character entered when a key is pressed, taking into account the current keyboard layout. For example, pressing the "A" key causes this property to return either "a" or "A", depending on whether the Shift key is pressed at the time. The Shift key itself does not produce a character. When pressed, it returns an empty string.
commandKey
Gets a boolean value that indicates whether the Windows/Cmd key is pressed. True means the Windows/Cmd key is pressed. False means it isn't.
Declaration
public bool commandKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
ctrlKey
Gets a boolean value that indicates whether the Ctrl key is pressed. True means the Ctrl key is pressed. False means it isn't.
Declaration
public bool ctrlKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
keyCode
The key code.
Declaration
public KeyCode keyCode { get; protected set; }
Property Value
Type | Description |
---|---|
KeyCode |
Implements
Remarks
This is the code of the physical key that was pressed. It doesn't take into account the keyboard layout, and it displays modifier keys, since a key was pressed. For example, pressing the "A" key will cause this property to return KeyCode.A regardless of whether the Shift key is pressed or not. The Shift key itself returns KeyCode.LeftShift since it is a physical key on the keyboard.
modifiers
Gets flags that indicate whether modifier keys (Alt, Ctrl, Shift, Windows/Cmd) are pressed.
Declaration
public EventModifiers modifiers { get; protected set; }
Property Value
Type | Description |
---|---|
EventModifiers |
Implements
shiftKey
Gets a boolean value that indicates whether the Shift key is pressed. True means the Shift key is pressed. False means it isn't.
Declaration
public bool shiftKey { get; }
Property Value
Type | Description |
---|---|
Boolean |
Implements
Methods
GetPooled(Event)
Gets a keyboard event from the event pool and initializes it with the given values. Use this
function instead of creating new events. Events obtained using this method need to be released
back to the pool. You can use Dispose()
to release them.
Declaration
public static T GetPooled(Event systemEvent)
Parameters
Type | Name | Description |
---|---|---|
Event | systemEvent | A keyboard IMGUI event. |
Returns
Type | Description |
---|---|
T | An initialized event. |
GetPooled(Char, KeyCode, EventModifiers)
Gets a keyboard event from the event pool and initializes it with the given values. Use this function
instead of creating new events. Events obtained using this method need to be released back to the pool.
You can use Dispose()
to release them.
Declaration
public static T GetPooled(char c, KeyCode keyCode, EventModifiers modifiers)
Parameters
Type | Name | Description |
---|---|---|
Char | c | The character for this event. |
KeyCode | keyCode | The key code for this event. |
EventModifiers | modifiers | Event modifier keys that are active for this event. |
Returns
Type | Description |
---|---|
T | An initialized event. |
Init()
Resets the event members to their initial values.
Declaration
protected override void Init()