Version

The input system provides access to the HID devices connected to the host machine. The global input system object can be retrieved using the GetInputSystem function.

Accessing a device

A list of devices connected to the host machine can be retrieved by calling the GetDevices function.

Use the GetDevice function to access an InputDevice from this list.

Reading a device state

It is the application programmer responsibility to call the Update function each time the input system and devices state needs to be refreshed. In most application, this will be done exactly once per frame.

The InputDevice key or button state can then be queried through KeyCode by using the following functions:

  • IsDown: Returns True if the key or button was down during the last update.
  • WasDown: Returns True if the key or button was down two updates ago.
  • WasPressed: Returns True if the key or button was down two updates ago and released during the last update.

These functions return a binary True/False value.

To read values from the device axises the GetValue and GetLastValue functions can be used together with [InputDevice_GetInputRange].

Reading from the Keyboard device

The main keyboard device connected to the host is always retrieved using the keyboard device identifier. All of the keyboard keys can be queried by using their corresponding KeyCode.

Reading from the Mouse device

The main mouse device connected to the host is always retrieved using the mouse device identifier. The mouse buttons state can be read from the KeyButton0 and upward key codes. The mouse cursor position can be read from the InputAxisX and InputAxisY input codes.

The mouse wheel is mapped to the InputAxisZ input code.

Platform-specific notes

Windows

The input system uses the platform SDK, Direct Input 8 and XInput to access HID devices. XInput device ports are easily identified as xinput0 to xinput3.

At the moment XInput only supports XBox 360 and XBox One controllers. If you need to use a controller such as the Playstation 4 one you should use its Direct Input 8 identifier (starting with di8-).