1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| GamepadMonitor::GamepadMonitor(QObject *parent)
: QObject(parent)
{
qDebug() << "QGamePadManager Demo\n";
auto gamepads = QGamepadManager::instance()->connectedGamepads();
qDebug() << "Number of gamepads:" << gamepads.size();
for (auto i : gamepads) {
QGamepad *gamepad = new QGamepad(i);
qDebug() << "Gamepad:" << i;
qDebug() << " device id: " << gamepad->deviceId();
qDebug() << " name: " << gamepad->name();
qDebug() << " is connected?" << gamepad->isConnected();
}
qDebug() << "\nMonitoring for events...\n";
connect(QGamepadManager::instance(), &QGamepadManager::connectedGamepadsChanged, this,
[]() { qDebug() << "connected gamepads changed:"; });
connect(QGamepadManager::instance(), &QGamepadManager::gamepadConnected, this,
[](int deviceId) { qDebug() << "gamepad connected:" << deviceId; });
connect(QGamepadManager::instance(), &QGamepadManager::gamepadDisconnected, this,
[](int deviceId) { qDebug() << "gamepad disconnected:" << deviceId; });
connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonPressEvent, this,
[](int deviceId, QGamepadManager::GamepadButton button, double value) { qDebug() << "button press event:" << deviceId << button << value; });
connect(QGamepadManager::instance(), &QGamepadManager::gamepadButtonReleaseEvent, this,
[](int deviceId, QGamepadManager::GamepadButton button) { qDebug() << "button release event:" << deviceId << button; });
connect(QGamepadManager::instance(), &QGamepadManager::gamepadAxisEvent, this,
[](int deviceId, QGamepadManager::GamepadAxis axis, double value) { qDebug() << "axis event:" << deviceId << axis << value; });
connect(QGamepadManager::instance(), &QGamepadManager::buttonConfigured, this,
[](int deviceId, QGamepadManager::GamepadButton button) { qDebug() << "button configured:" << deviceId << button; });
connect(QGamepadManager::instance(), &QGamepadManager::axisConfigured, this,
[](int deviceId, QGamepadManager::GamepadAxis axis) { qDebug() << "axis configured:" << deviceId << axis; });
connect(QGamepadManager::instance(), &QGamepadManager::configurationCanceled, this,
[](int deviceId) { qDebug() << "configuration canceled:" << deviceId; });
} |
Partager