Skip to content

GamepadEvent ​

Represents a gamepad input event.

A gamepad event is dispatched when a gamepad is connected or disconnected, a button is pressed or released, or an axis changes. It extends the base Event with data specific to gamepad input: the interaction type, the gamepad id, and the button or axis involved.

Gamepad events are dispatched through the Scene hierarchy where nodes can override the Node::OnGamepadEvent handler and optionally mark the event as handled. When handled is set to true the event stops propagating to other nodes.

cpp
class MyNode : public vglx::Node {
public:
  auto OnGamepadEvent(vglx::GamepadEvent* event) -> void override {
    if (event->type == vglx::GamepadEvent::Type::ButtonPressed) {
      if (event->button == vglx::GamepadButton::RightFaceDown) {
        // Do something...
        event->handled = true; // stop propagation
      }
    }
  }
};

INFO

Derives from Event and inherits all public properties and methods.

Types ​

GamepadEvent::Type enum ​

Enumerates all gamepad event types.

Distinguishes between connection changes, button transitions, and axis changes.

ValueDescription
ConnectedGamepad was connected.
DisconnectedGamepad was disconnected.
ButtonPressedButton transitioned to the down state.
ButtonReleasedButton transitioned to the up state.
AxisMovedAxis value changed.

Properties ​

axis GamepadAxis ​

Gamepad axis associated with the event, if any.

Refer to the source code for enum details.

cpp
GamepadAxis axis {};

button GamepadButton ​

Gamepad button associated with the event, if any.

Refer to the source code for enum details.

cpp
GamepadButton button {};

gamepad int ​

Identifier of the gamepad that generated the event.

Stable for as long as the gamepad stays connected.

cpp
int gamepad {};

The interaction type for this event.

cpp
GamepadEvent::Type type {};

value float ​

Current value of the axis.

Sticks range from -1 to 1, with positive Y pointing down, and read 0 inside a small deadzone. Triggers range from 0 (released) to 1.

cpp
float value {};

Functions ​

GetType() Event::Type virtual ​

Identifies this event as Event::Type::Gamepad.

cpp
Type vglx::GamepadEvent::GetType() const override;

Released under the MIT License.