ShatteredPrism/launcher/KonamiCode.cpp
Reider745 60234a550b
Some checks failed
CodeQL Code Scanning / CodeQL (push) Has been cancelled
Build Application / Build Debug (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (macos-13, x86_64-darwin) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (macos-14, aarch64-darwin) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (ubuntu-22.04, x86_64-linux) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (ubuntu-22.04-arm, aarch64-linux) (push) Has been cancelled
Update Flake Lockfile / update-flake (push) Has been cancelled
feat: auto install modpack & choise nickname
2025-04-15 11:13:45 +03:00

29 lines
827 B
C++
Executable File

#include "KonamiCode.h"
#include <QDebug>
#include <array>
namespace {
const std::array<Qt::Key, 10> konamiCode = { { Qt::Key_Up, Qt::Key_Up, Qt::Key_Down, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right,
Qt::Key_Left, Qt::Key_Right, Qt::Key_B, Qt::Key_A } };
}
KonamiCode::KonamiCode(QObject* parent) : QObject(parent) {}
void KonamiCode::input(QEvent* event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
auto key = Qt::Key(keyEvent->key());
if (key == konamiCode[m_progress]) {
m_progress++;
} else {
m_progress = 0;
}
if (m_progress == static_cast<int>(konamiCode.size())) {
m_progress = 0;
emit triggered();
}
}
}