GamepadEvent
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.
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.
| Value | Description |
|---|---|
| Connected | Gamepad was connected. |
| Disconnected | Gamepad was disconnected. |
| ButtonPressed | Button transitioned to the down state. |
| ButtonReleased | Button transitioned to the up state. |
| AxisMoved | Axis value changed. |
Properties
axis GamepadAxis
Gamepad axis associated with the event, if any.
Refer to the source code for enum details.
GamepadAxis axis {};button GamepadButton
Gamepad button associated with the event, if any.
Refer to the source code for enum details.
GamepadButton button {};gamepad int
Identifier of the gamepad that generated the event.
Stable for as long as the gamepad stays connected.
int gamepad {};type GamepadEvent::Type
The interaction type for this event.
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.
float value {};Functions
GetType() Event::Type virtual
Identifies this event as Event::Type::Gamepad.
Type vglx::GamepadEvent::GetType() const override;