ezEngine  Milestone 9
ezInputDevice Class Referenceabstract

The base class for all input device types. More...

#include <InputDevice.h>

Inheritance diagram for ezInputDevice:

Public Member Functions

 ezInputDevice ()
 Default Constructor.
- Public Member Functions inherited from ezReflectedClass
virtual const ezRTTIGetDynamicRTTI () const
EZ_ALWAYS_INLINE bool IsInstanceOf (const ezRTTI *pType) const
 Returns whether the type of this instance is of the given type or derived from it.
template<typename T >
EZ_ALWAYS_INLINE bool IsInstanceOf () const
 Returns whether the type of this instance is of the given type or derived from it.

Static Protected Member Functions

static void RegisterInputSlot (const char *szName, const char *szDefaultDisplayName, ezBitflags< ezInputSlotFlags > SlotFlags)
 Calls RegisterInputSlot() on the ezInputManager and passes the parameters through.

Protected Attributes

ezMap< ezString, float > m_InputSlotValues
 Stores all the values for all input slots that this device handles. More...
ezUInt32 m_LastCharacter
 If this input device type handles character input, it should write the last typed character into this variable. The ezInputManager calls RetrieveLastCharacter() to query what the user typed last.
- Protected Attributes inherited from ezEnumerable< ezInputDevice, ezReflectedClass >


class ezInputManager

Additional Inherited Members

- Static Public Member Functions inherited from ezNoBase
static const ezRTTIGetStaticRTTI ()

Detailed Description

The base class for all input device types.

An input device is the abstraction of one or more types of input. It is not linked to one physical device. For example an input device can represent mouse AND keyboard (through one class). Another input device can represent all connected controllers (e.g. up to 4 XBox 360 controllers). On OSes where applications can have several windows, an input device may also represent all input from one window, if required.

An input device is the abstraction layer for the hardware input. All keys, movements etc. are mapped to named 'input slots', which typically hold a value between 0 and 1, where 0 represents 'not pressed' and 1 represents 'fully pressed'. All hardware that has a finite range (such as buttons, analog triggers, the positive/negative axis of analog sticks) should try to map to this range. Even mouse coordinates are typically mapped to the 0 to 1 range, where zero means top/left and 1 means bottom/right.

All input handling is usually handled through the ezInputManager class. A user should typically not have to interact directly with an input device, unless he needs to call device specific functions for advanced configuration.

An input device defines which input slots it exposes to the engine. All input slots are handled by name (e.g. string). For example a keyboard would expose the input slots 'keyboard_a' to 'keyboard_z' and other keys. A mouse would expose slots such as 'mouse_move_pos_x' and 'mouse_move_neg_x' etc.

By deriving from ezInputDevice you can extend what hardware the engine supports. The derived class should override InitializeDevice() to do hardware specific setup. It also needs to override RegisterInputSlots() to register all the input slots that it wants to expose from the hardware. E.g. if the device wants to expose values from a gyroscope, it should register input slots that represent the rotations around the different axis (one slot each for both positive and negative changes). It then also needs to implement UpdateInputSlotValues() and/or ResetInputSlotValues() and possible a device-specific update function, to get the input values. For example on Windows a platform/device specific update function is necessary to parse the incoming window messages. If such a device specific function is necessary, it also needs to be integrated into the proper code (e.g. into the window handling code, to be able to get the window messages). In such a case it might not be possible to add such a device purely through a dynamic plugin, but might also need deeper integration into other engine code.

Member Data Documentation

◆ m_InputSlotValues

ezMap<ezString, float> ezInputDevice::m_InputSlotValues

Stores all the values for all input slots that this device handles.

A derived class needs to fill out this map every frame. There are two ways this map can be filled out. For devices where you can query the complete state at one point in time (e.g. controllers), you can update the entire map inside an overridden UpdateInputSlotValues() function. For devices where you get the input only piece-wise and usually only when something changes (e.g. through messages) you can also just update the map whenever input arrives. However in such a use-case you sometimes need to manually reset the state of certain input slots. For example when a mouse-move message arrives that movement delta is accumulated in the map. However, when the mouse stops usually no 'mouse stopped' message is sent but the values in the map need to be reset to zero, to prevent the mouse from keeping moving in the engine. Do this inside an overridden ResetInputSlotValues() function. You don't need to do this for input slots that will reset to zero anyway.

The documentation for this class was generated from the following files: