Struct InputEvent
A chunk of memory signaling a data transfer in the input system.
Namespace: UnityEngine .InputSystem .LowLevel
Assembly: Unity.InputSystem.dll
Syntax
public struct InputEvent
Remarks
Input events are raw memory buffers akin to a byte array. For most uses of the input
system, it is not necessary to be aware of the event stream in the background. Events
are written to the internal event buffer by producers -- usually by the platform-specific
backends sitting in the Unity runtime. Once per fixed or dynamic update (depending on
what update
Events may signal general device-related occurrences (such as Device
Events are solely focused on input. To effect output on an input device (e.g. haptics
effects), "commands" (see Input
Event processing can be listened to using on
Note that there is no "routing" mechanism for events, i.e. no mechanism by which the input
system looks for a handler for a specific event. Instead, events represent low-level activity
that the input system directly integrates into the state of its Input
Each type of event is distinguished by its own Four
Each event will receive a unique ID when queued to the internal event buffer. The ID can
be queried using the event
All events are device-specific meaning that device
Constructors
InputEvent(FourCC, int, int, double)
Declaration
public InputEvent(FourCC type, int sizeInBytes, int deviceId, double time = -1)
Parameters
See Also
Fields
InvalidEventId
Default, invalid value for event
Declaration
public const int InvalidEventId = 0
Field Value
Type | Description |
---|---|
int |
See Also
Properties
deviceId
ID of the device that the event is for.
Declaration
public int deviceId { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
Device IDs are allocated by the runtime. No two devices will receive the same ID over an application lifecycle regardless of whether the devices existed at the same time or not.
See Also
eventId
Unique serial ID of the event.
Declaration
public int eventId { get; set; }
Property Value
Type | Description |
---|---|
int |
Remarks
Events are assigned running IDs when they are put on an event queue (see
Queue
See Also
handled
Declaration
public bool handled { get; set; }
Property Value
Type | Description |
---|---|
bool |
See Also
sizeInBytes
Total size of the event in bytes.
Declaration
public uint sizeInBytes { get; set; }
Property Value
Type | Description |
---|---|
uint | Size of the event in bytes. |
Remarks
Events are variable-size structs. This field denotes the total size of the event as stored in memory. This includes the full size of this struct and not just the "payload" of the event.
// Store event in private buffer:
unsafe byte[] CopyEventData(InputEventPtr eventPtr)
{
var sizeInBytes = eventPtr.sizeInBytes;
var buffer = new byte[sizeInBytes];
fixed (byte* bufferPtr = buffer)
{
UnsafeUtility.MemCpy(new IntPtr(bufferPtr), eventPtr.data, sizeInBytes);
}
return buffer;
}
The maximum supported size of events is ushort.MaxValue
, i.e. events cannot
be larger than 64KB.
Exceptions
Type | Condition |
---|---|
Argument |
|
See Also
time
Time that the event was generated at.
Declaration
public double time { get; set; }
Property Value
Type | Description |
---|---|
double |
Remarks
Times are in seconds and progress linearly in real-time. The timeline is the
same as for realtime
Note that this implies that event times will reset in the editor every time you
go into play mode. In effect, this can result in events appearing with negative
timestamps (i.e. the event was generated before the current zero point for
realtime
See Also
type
Type code for the event.
Declaration
public FourCC type { get; set; }
Property Value
Type | Description |
---|---|
Four |
Remarks
Each type of event has its own unique FourCC tag. For example, state events (see StateType
property (for example, Type).
To check whether an event has a specific type tag, you can use Is
See Also
Methods
Equals(InputEvent*, InputEvent*)
Declaration
public static bool Equals(InputEvent* first, InputEvent* second)
Parameters
Type | Name | Description |
---|---|---|
Input |
first | |
Input |
second |
Returns
Type | Description |
---|---|
bool |
See Also
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |