Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


KeyboardEventBase<T>

This is the base class for keyboard events.
Read time 3 minutesLast updated 2 days ago

Definition

public abstract class KeyboardEventBase<T> : EventBase<T>, IDisposable, IKeyboardEvent where T : KeyboardEventBase<T>, new()

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. disabled elements won't receive these events.
Refer to the Keyboard events manual page for more information and examples.
Additional Resources: KeyDownEvent, KeyUpEvent

Properties

Property

Description

actionKeyGets a boolean value that indicates whether the platform-specific action key is pressed.
altKeyGets a boolean value that indicates whether the Alt key is pressed.
characterGets the character entered.
commandKeyGets a boolean value that indicates whether the Windows/Cmd key is pressed.
ctrlKeyGets a boolean value that indicates whether the Ctrl key is pressed.
keyCodeThe key code.
modifiersGets flags that indicate whether modifier keys (Alt, Ctrl, Shift, Windows/Cmd) are pressed.
shiftKeyGets a boolean value that indicates whether the Shift key is pressed.

Methods

Method

Description

InitResets the event members to their initial values.

Static Methods

Method

Description

GetPooledGets 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.

Inheritance