From 1ef76e04ac30b841f66669a1ea2f3bf72867841c Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:10:40 +0530 Subject: [PATCH 01/31] Add Mouse_pointer --- CMakeLists.txt | 9 ++- src/main.cpp | 1 + src/mainwindow.cpp | 6 ++ src/mainwindow.hpp | 3 + src/mainwindow.ui | 9 ++- src/networking/executor.cpp | 10 +-- src/networking/executor.hpp | 2 + src/preferences.cpp | 30 +++++++++ src/preferences.h | 23 +++++++ src/preferences.ui | 129 ++++++++++++++++++++++++++++++++++++ 10 files changed, 212 insertions(+), 10 deletions(-) create mode 100644 src/preferences.cpp create mode 100644 src/preferences.h create mode 100644 src/preferences.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 14939e7..54bf595 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,8 @@ set(THIRD_PARTY_LIB_SOURCES third-party-libs/QR-Code-generator/cpp/qrcodegen.hpp ) -add_library(QR_Code_Generator SHARED ${THIRD_PARTY_LIB_SOURCES}) +add_library(QR_Code_Generator SHARED ${THIRD_PARTY_LIB_SOURCES} +) set(PROJECT_SOURCES src/main.cpp @@ -44,6 +45,12 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(VGamepadPC MANUAL_FINALIZATION ${PROJECT_SOURCES} + src/preferences.h src/preferences.cpp src/preferences.ui + + + + + ) # Define target properties for Android with Qt 6 as: # set_property(TARGET VGamepadPC APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR diff --git a/src/main.cpp b/src/main.cpp index bc2c6c0..79e16e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "mainwindow.hpp" diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0221311..4f33d11 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2,10 +2,16 @@ #include "networking/server.hpp" #include "ui_mainwindow.h" +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + this->p = new Preferences(this); ui->setupUi(this); + ui->pushButton->connect(ui->pushButton, &QPushButton::pressed, this, [=]{ + this->p->show(); + }); + } MainWindow::~MainWindow() diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index b79569b..a5767f2 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include "preferences.h" QT_BEGIN_NAMESPACE namespace Ui @@ -22,4 +23,6 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; + Preferences *p = nullptr; + }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index d1794d3..7c714cd 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -29,6 +29,13 @@ + + + + Preferences + + + @@ -37,7 +44,7 @@ 0 0 800 - 26 + 17 diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index 94feef8..3808c77 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -3,7 +3,7 @@ #include #define THRESHOLD 0.5 -#define MOUSE_SENSITIVITY 1000 + vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t len) { @@ -72,13 +72,7 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) // Use the right thumbstick to move the mouse // if (abs(reading.right_thumbstick_x) > THRESHOLD || abs(reading.right_thumbstick_y) > THRESHOLD) - int offsetX = reading.right_thumbstick_x * MOUSE_SENSITIVITY; - int offsetY = reading.right_thumbstick_y * MOUSE_SENSITIVITY; - int scaleX = abs(offsetX) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; - int scaleY = abs(offsetY) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; - - qDebug() << "Moving mouse by" << offsetX << ", " << offsetY; - for (int count = 1; count <= std::max(abs(offsetX), abs(offsetY)); ++count) + for (int count = 1; count <= mouse_sensivity; ++count) { int stepX = std::copysign(scaleX, offsetX); int stepY = std::copysign(scaleY, offsetY); diff --git a/src/networking/executor.hpp b/src/networking/executor.hpp index 5162c80..b8b0e6b 100644 --- a/src/networking/executor.hpp +++ b/src/networking/executor.hpp @@ -6,6 +6,8 @@ #include +inline int mouse_sensivity = 1000; + vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t len); bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading); diff --git a/src/preferences.cpp b/src/preferences.cpp new file mode 100644 index 0000000..4a6ed24 --- /dev/null +++ b/src/preferences.cpp @@ -0,0 +1,30 @@ +#include "preferences.h" +#include "ui_preferences.h" +#include "networking/executor.hpp" +#include +#include + +Preferences::Preferences(QWidget *parent) : + QDialog(parent), + ui(new Ui::Preferences) +{ + ui->setupUi(this); + ui->horizontalSlider->adjustSize(); + this->adjustSize(); + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]{ + this->change_mouse_sensitivity(ui->horizontalSlider->value()*100); + qDebug() << mouse_sensivity << Qt::endl; + }); + +} + +int Preferences::change_mouse_sensitivity(int value) { + mouse_sensivity = value; + return 1; +} + + +Preferences::~Preferences() +{ + delete ui; +} diff --git a/src/preferences.h b/src/preferences.h new file mode 100644 index 0000000..7ee9953 --- /dev/null +++ b/src/preferences.h @@ -0,0 +1,23 @@ +#ifndef PREFERENCES_H +#define PREFERENCES_H + +#include + +namespace Ui { +class Preferences; +} + +class Preferences : public QDialog +{ + Q_OBJECT + + public: + explicit Preferences(QWidget *parent = nullptr); + ~Preferences(); + + private: + Ui::Preferences *ui; + int change_mouse_sensitivity(int value); +}; + +#endif // PREFERENCES_H diff --git a/src/preferences.ui b/src/preferences.ui new file mode 100644 index 0000000..f7e79cf --- /dev/null +++ b/src/preferences.ui @@ -0,0 +1,129 @@ + + + Preferences + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + 40 + 60 + 282 + 34 + + + + + + + + 16777215 + 16777215 + + + + + true + + + + Pointer Speed + + + 10 + + + + + + + + 140 + 0 + + + + + 140 + 16777215 + + + + 1 + + + 20 + + + 10 + + + Qt::Horizontal + + + + + + + + + + buttonBox + accepted() + Preferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Preferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + From cc2f07cece6bc3b6605e3d2661c56c95dd38831d Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:14:40 +0530 Subject: [PATCH 02/31] Update executor.cpp --- src/networking/executor.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index 3808c77..50a4cec 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -72,7 +72,13 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) // Use the right thumbstick to move the mouse // if (abs(reading.right_thumbstick_x) > THRESHOLD || abs(reading.right_thumbstick_y) > THRESHOLD) - for (int count = 1; count <= mouse_sensivity; ++count) + int offsetX = reading.right_thumbstick_x * MOUSE_SENSITIVITY; + int offsetY = reading.right_thumbstick_y * MOUSE_SENSITIVITY; + int scaleX = abs(offsetX) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; + int scaleY = abs(offsetY) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; + + qDebug() << "Moving mouse by" << offsetX << ", " << offsetY; + for (int count = 1; count <= std::max(abs(offsetX), abs(offsetY)); ++count) { int stepX = std::copysign(scaleX, offsetX); int stepY = std::copysign(scaleY, offsetY); From 793496096b0f2e442c892ba4ebf977fc9aa2d58d Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 6 Aug 2023 20:16:53 +0530 Subject: [PATCH 03/31] changing the mouse_sensitivity_variable --- src/networking/executor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index 50a4cec..9f09e5f 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -72,10 +72,10 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) // Use the right thumbstick to move the mouse // if (abs(reading.right_thumbstick_x) > THRESHOLD || abs(reading.right_thumbstick_y) > THRESHOLD) - int offsetX = reading.right_thumbstick_x * MOUSE_SENSITIVITY; - int offsetY = reading.right_thumbstick_y * MOUSE_SENSITIVITY; - int scaleX = abs(offsetX) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; - int scaleY = abs(offsetY) < (THRESHOLD * MOUSE_SENSITIVITY) ? 0 : 1; + int offsetX = reading.right_thumbstick_x * mouse_sensivity; + int offsetY = reading.right_thumbstick_y * mouse_sensivity; + int scaleX = abs(offsetX) < (THRESHOLD * mouse_sensivity) ? 0 : 1; + int scaleY = abs(offsetY) < (THRESHOLD * mouse_sensivity) ? 0 : 1; qDebug() << "Moving mouse by" << offsetX << ", " << offsetY; for (int count = 1; count <= std::max(abs(offsetX), abs(offsetY)); ++count) From 3bb24ceab3166673a82be8a8a93a828aaeafd79f Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 9 Aug 2023 21:40:03 +0530 Subject: [PATCH 04/31] updating PROJECT_SOURCES --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 54bf595..e489d29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,13 +39,23 @@ set(PROJECT_SOURCES src/networking/executor.cpp src/networking/executor.hpp res/icons.qrc + src/preferences.h + src/preferences.cpp + src/preferences.ui + src/settings.h + src/settings.cpp + src/settings_key_variables.h + src/settings_key_variables.cpp ) if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(VGamepadPC MANUAL_FINALIZATION ${PROJECT_SOURCES} - src/preferences.h src/preferences.cpp src/preferences.ui + + + + From 7db3439ce356d41b5c88e44c5f09121560d6218f Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:06:21 +0530 Subject: [PATCH 05/31] created programmable variables changed all static hard coded values to variables and included them in a separate folder --- VGP_Data_Exchange | 2 +- src/main.cpp | 3 +- src/mainwindow.cpp | 8 ++--- src/mainwindow.hpp | 3 +- src/networking/executor.cpp | 1 + src/networking/executor.hpp | 38 +---------------------- src/networking/server.cpp | 3 +- src/preferences.cpp | 20 ++++++------- src/preferences.h | 3 +- src/preferences.ui | 34 +++++++++++++++++---- src/settings.cpp | 55 ++++++++++++++++++++++++++++++++++ src/settings.h | 40 +++++++++++++++++++++++++ src/settings_key_variables.cpp | 24 +++++++++++++++ src/settings_key_variables.h | 26 ++++++++++++++++ src/simulation/keyboardSim.cpp | 12 ++++---- src/simulation/keyboardSim.hpp | 2 +- src/simulation/mouseSim.hpp | 2 +- 17 files changed, 205 insertions(+), 71 deletions(-) create mode 100644 src/settings.cpp create mode 100644 src/settings.h create mode 100644 src/settings_key_variables.cpp create mode 100644 src/settings_key_variables.h diff --git a/VGP_Data_Exchange b/VGP_Data_Exchange index faa4365..463ebd3 160000 --- a/VGP_Data_Exchange +++ b/VGP_Data_Exchange @@ -1 +1 @@ -Subproject commit faa4365088537eeec22cdd2e88c71521ede27ed8 +Subproject commit 463ebd330326616af44a89f9bdf41edc238d8b92 diff --git a/src/main.cpp b/src/main.cpp index 79e16e6..f192b48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ +#include "settings.h" #include -#include #include +#include #include "mainwindow.hpp" diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4f33d11..fc3de2c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,17 +1,17 @@ #include "mainwindow.hpp" #include "networking/server.hpp" +#include "settings.h" #include "ui_mainwindow.h" #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + load_settings_file(this); + load_mouse_setting(); this->p = new Preferences(this); ui->setupUi(this); - ui->pushButton->connect(ui->pushButton, &QPushButton::pressed, this, [=]{ - this->p->show(); - }); - + ui->pushButton->connect(ui->pushButton, &QPushButton::pressed, this, [=] { this->p->show(); }); } MainWindow::~MainWindow() diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index a5767f2..86eaf75 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -1,7 +1,7 @@ #pragma once -#include #include "preferences.h" +#include QT_BEGIN_NAMESPACE namespace Ui @@ -24,5 +24,4 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; Preferences *p = nullptr; - }; diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index 9f09e5f..b0d1f2d 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -1,4 +1,5 @@ #include "executor.hpp" +#include "../settings_key_variables.h" #include diff --git a/src/networking/executor.hpp b/src/networking/executor.hpp index b8b0e6b..0d92425 100644 --- a/src/networking/executor.hpp +++ b/src/networking/executor.hpp @@ -1,46 +1,10 @@ #pragma once #include "../../VGP_Data_Exchange/C/Colfer.h" -#include "../../VGP_Data_Exchange/C/GameButtons.h" #include "../simulation/simulate.hpp" -#include -inline int mouse_sensivity = 1000; + vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t len); bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading); - -// Map of gamepad buttons to keyboard keys -const std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, - {GamepadButtons::GamepadButtons_View, VK_TAB}, - {GamepadButtons::GamepadButtons_A, VK_RETURN}, - {GamepadButtons::GamepadButtons_B, VK_ESCAPE}, - {GamepadButtons::GamepadButtons_X, VK_SHIFT}, - {GamepadButtons::GamepadButtons_Y, VK_CONTROL}, - {GamepadButtons::GamepadButtons_DPadUp, VK_UP}, - {GamepadButtons::GamepadButtons_DPadDown, VK_DOWN}, - {GamepadButtons::GamepadButtons_DPadLeft, VK_LEFT}, - {GamepadButtons::GamepadButtons_DPadRight, VK_RIGHT}, - {GamepadButtons::GamepadButtons_LeftShoulder, 'E'}, - {GamepadButtons::GamepadButtons_RightShoulder, VK_SPACE}, - {GamepadButtons::GamepadButtons_LeftThumbstick, VK_PRIOR}, - {GamepadButtons::GamepadButtons_RightThumbstick, VK_NEXT}}; - -enum Thumbstick -{ - LeftThumbstickUp, - LeftThumbstickDown, - LeftThumbstickLeft, - LeftThumbstickRight, - RightThumbstickUp, - RightThumbstickDown, - RightThumbstickLeft, - RightThumbstickRight -}; - -const std::map THUMBSTICK_KEYS = { - {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, - {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, - {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, - {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; diff --git a/src/networking/server.cpp b/src/networking/server.cpp index 941d935..40902b5 100644 --- a/src/networking/server.cpp +++ b/src/networking/server.cpp @@ -5,6 +5,7 @@ #include "../../VGP_Data_Exchange/C/Colfer.h" #include "../../third-party-libs/QR-Code-generator/cpp/qrcodegen.hpp" +#include "../settings_key_variables.h" #include #include @@ -73,7 +74,7 @@ Server::~Server() void Server::initServer() { tcpServer->setListenBacklogSize(0); - if (!tcpServer->listen(QHostAddress::AnyIPv4, 7878)) + if (!tcpServer->listen(QHostAddress::AnyIPv4, port)) { QMessageBox::critical(this, tr("VGamepad Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString())); diff --git a/src/preferences.cpp b/src/preferences.cpp index 4a6ed24..a7366e9 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -1,29 +1,29 @@ #include "preferences.h" +#include "settings_key_variables.h" +#include "settings.h" #include "ui_preferences.h" -#include "networking/executor.hpp" -#include #include +#include -Preferences::Preferences(QWidget *parent) : - QDialog(parent), - ui(new Ui::Preferences) +Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferences) { ui->setupUi(this); ui->horizontalSlider->adjustSize(); this->adjustSize(); - ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=]{ - this->change_mouse_sensitivity(ui->horizontalSlider->value()*100); + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=] { + this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); qDebug() << mouse_sensivity << Qt::endl; + save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); }); - + ui->horizontalSlider->setValue(mouse_sensivity / 100); } -int Preferences::change_mouse_sensitivity(int value) { +int Preferences::change_mouse_sensitivity(int value) +{ mouse_sensivity = value; return 1; } - Preferences::~Preferences() { delete ui; diff --git a/src/preferences.h b/src/preferences.h index 7ee9953..142902c 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -3,7 +3,8 @@ #include -namespace Ui { +namespace Ui +{ class Preferences; } diff --git a/src/preferences.ui b/src/preferences.ui index f7e79cf..7abd2c0 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -11,17 +11,20 @@ - Dialog + Preferences - 30 + 210 240 - 341 + 161 32 + + ArrowCursor + Qt::Horizontal @@ -29,12 +32,25 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + 40 - 60 - 282 + 110 + 281 + 111 + + + + Key Maps + + + + + + 41 + 61 + 281 34 @@ -86,6 +102,12 @@ Qt::Horizontal + + QSlider::TicksAbove + + + 5 + diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..7d3682f --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,55 @@ +#include "settings.h" +#include "settings_key_variables.h" +#include + +QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.Ini"); +QSettings *settings; + +QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; + +void save_setting(QString key, QVariant value) +{ + settings->setValue(key, value); + settings->sync(); + qDebug() << settings->value(key).toString() << Qt::endl; + qDebug() << settings->fileName() << Qt::endl; +} + +QVariant load_setting(QString key) +{ + QVariant value = settings->value(key); + return value; +} + +void load_mouse_setting() +{ + mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; +} + +void load_settings_file(QObject *parent = nullptr) +{ + settings = new QSettings(SETTINGS_FILE, QSettings::Format::IniFormat, parent); +} + +void set_port_number(int custom_port) { + settings->setValue(server_settings[setting_keys::Port], custom_port); +} + +void load_port_number() { + port = settings->value(server_settings[setting_keys::Port]).toInt(); +} + +void set_key_maps(setting_keys::keys a,WORD value) { + settings->setValue(keymaps[a], value); +} + +void load_key_maps() { + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = (WORD)settings->value(keymaps[setting_keys::keys::A]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = (WORD)settings->value(keymaps[setting_keys::keys::B]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = (WORD)settings->value(keymaps[setting_keys::keys::X]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = (WORD)settings->value(keymaps[setting_keys::keys::Y]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::LT]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::RT]).toULongLong(); +} + + diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..f8a886c --- /dev/null +++ b/src/settings.h @@ -0,0 +1,40 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#endif // SETTINGS_H +#include +#include + +extern QString SETTINGS_FILE; + +namespace setting_keys +{ + +enum server_keys +{ + Port +}; + +extern QString Mouse_sensivity; + +enum keys +{ + A, + B, + X, + Y, + RT, + LT +}; + +} // namespace setting_keys + +extern QSettings *settings; +inline QList server_settings = {"port"}; +inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; + +void save_setting(QString key, QVariant value); +QVariant load_setting(QString key); +void load_mouse_setting(); +void load_settings_file(QObject *parent); +void load_port_number(); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp new file mode 100644 index 0000000..5a3531f --- /dev/null +++ b/src/settings_key_variables.cpp @@ -0,0 +1,24 @@ +#include "settings_key_variables.h" + +int mouse_sensivity = 1000; +int port = 7878; +std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, + {GamepadButtons::GamepadButtons_View, VK_TAB}, + {GamepadButtons::GamepadButtons_A, VK_RETURN}, + {GamepadButtons::GamepadButtons_B, VK_ESCAPE}, + {GamepadButtons::GamepadButtons_X, VK_SHIFT}, + {GamepadButtons::GamepadButtons_Y, VK_CONTROL}, + {GamepadButtons::GamepadButtons_DPadUp, VK_UP}, + {GamepadButtons::GamepadButtons_DPadDown, VK_DOWN}, + {GamepadButtons::GamepadButtons_DPadLeft, VK_LEFT}, + {GamepadButtons::GamepadButtons_DPadRight, VK_RIGHT}, + {GamepadButtons::GamepadButtons_LeftShoulder, 'E'}, + {GamepadButtons::GamepadButtons_RightShoulder, VK_SPACE}, + {GamepadButtons::GamepadButtons_LeftThumbstick, VK_PRIOR}, + {GamepadButtons::GamepadButtons_RightThumbstick, VK_NEXT}}; + +std::map THUMBSTICK_KEYS = { + {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, + {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, + {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, + {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h new file mode 100644 index 0000000..9f7f7d1 --- /dev/null +++ b/src/settings_key_variables.h @@ -0,0 +1,26 @@ +#pragma once +#ifndef SETTINGS_KEY_VARIABLES_H +#define SETTINGS_KEY_VARIABLES_H +#include +#endif // SETTINGS_KEY_VARIABLES_H + +#include +#include "../VGP_Data_Exchange/C/GameButtons.h" + +extern int mouse_sensivity; +extern int port; +extern std::map GAMEPAD_BUTTONS; + +enum Thumbstick +{ + LeftThumbstickUp, + LeftThumbstickDown, + LeftThumbstickLeft, + LeftThumbstickRight, + RightThumbstickUp, + RightThumbstickDown, + RightThumbstickLeft, + RightThumbstickRight +}; + +extern std::map THUMBSTICK_KEYS; diff --git a/src/simulation/keyboardSim.cpp b/src/simulation/keyboardSim.cpp index 0d7064c..38b5bee 100644 --- a/src/simulation/keyboardSim.cpp +++ b/src/simulation/keyboardSim.cpp @@ -78,13 +78,13 @@ void typeUnicodeString(std::wstring str) for (size_t i = 0; i < str.size(); i++) { // Press the key - inputs[2*i].type = INPUT_KEYBOARD; - inputs[2*i].ki.wScan = str[i]; - inputs[2*i].ki.dwFlags = KEYEVENTF_UNICODE; + inputs[2 * i].type = INPUT_KEYBOARD; + inputs[2 * i].ki.wScan = str[i]; + inputs[2 * i].ki.dwFlags = KEYEVENTF_UNICODE; // Release the key - inputs[2*i+1].type = INPUT_KEYBOARD; - inputs[2*i+1].ki.wScan = str[i]; - inputs[2*i+1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP; + inputs[2 * i + 1].type = INPUT_KEYBOARD; + inputs[2 * i + 1].ki.wScan = str[i]; + inputs[2 * i + 1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP; } SendInput(str.size() * 2, inputs.data(), sizeof(INPUT)); } diff --git a/src/simulation/keyboardSim.hpp b/src/simulation/keyboardSim.hpp index 5d6e691..f3c4162 100644 --- a/src/simulation/keyboardSim.hpp +++ b/src/simulation/keyboardSim.hpp @@ -1,7 +1,7 @@ /** * @file keyboardSim.hpp * @brief Simulates keyboard input in Windows. - * + * * @note Do not include this file directly. Use @link simulate.hpp @endlink instead. */ #pragma once diff --git a/src/simulation/mouseSim.hpp b/src/simulation/mouseSim.hpp index 33689f8..3712ff1 100644 --- a/src/simulation/mouseSim.hpp +++ b/src/simulation/mouseSim.hpp @@ -1,7 +1,7 @@ /** * @file mouseSim.hpp * @brief Simulates mouse input in Windows. - * + * * @note Do not include this file directly. Use @link simulate.hpp @endlink instead. */ #pragma once From 921ae75dbc90191b0240438a0ee4e5466c3e1df7 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sat, 19 Aug 2023 11:31:57 +0530 Subject: [PATCH 06/31] Update CMakeLists.txt removed extra spaces --- CMakeLists.txt | 9 --------- 1 file changed, 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e489d29..bdadabf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,15 +52,6 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) qt_add_executable(VGamepadPC MANUAL_FINALIZATION ${PROJECT_SOURCES} - - - - - - - - - ) # Define target properties for Android with Qt 6 as: # set_property(TARGET VGamepadPC APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR From 590fcbc308621335737225e7de5dfae1ba21dd87 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 23 Aug 2023 16:20:37 +0530 Subject: [PATCH 07/31] adding icons icons for preference buttons --- res/logos/icons8-xbox-a-30.png | Bin 0 -> 459 bytes res/logos/icons8-xbox-b-30.png | Bin 0 -> 441 bytes res/logos/icons8-xbox-lt-30.png | Bin 0 -> 390 bytes res/logos/icons8-xbox-rt-30.png | Bin 0 -> 414 bytes res/logos/icons8-xbox-x-30.png | Bin 0 -> 481 bytes res/logos/icons8-xbox-y-30.png | Bin 0 -> 442 bytes 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 res/logos/icons8-xbox-a-30.png create mode 100644 res/logos/icons8-xbox-b-30.png create mode 100644 res/logos/icons8-xbox-lt-30.png create mode 100644 res/logos/icons8-xbox-rt-30.png create mode 100644 res/logos/icons8-xbox-x-30.png create mode 100644 res/logos/icons8-xbox-y-30.png diff --git a/res/logos/icons8-xbox-a-30.png b/res/logos/icons8-xbox-a-30.png new file mode 100644 index 0000000000000000000000000000000000000000..bd4aa0147f544bc5a169cd6b73426b20631e4d54 GIT binary patch literal 459 zcmV;+0W|)JP)?K@^2Q(ZAy$AE@Bl=> zr$i)kO`w#g;4;t!hQN;}M!*fQnpJcgh!uk4F#sB&q6d;eT2VXuc1Wh945GHUI`d+n zy)N6AG{RRoiY9TcIWn5+ty`SBV*OB@oQSq!lQ&?_;+Sz?!P|EU-zzpaleJ}FLB?GL z@75*!tk|F?YY%}P8P^oN$R!-7u=x?Vl<};>?l_BZ$0|be`vsVhxsHeX;SzrGkgE=E z)x+(D7FS;^HCU74DqF|IJbMi-uBL-{B5TY$ez)e$pG|P=;P1MGOO6JT*jyQ#{{rUa z+4=dec5 z<+YW4Sp&W=5SrSpW@K#Lo7IeDQjM4IC@MC14(ym2++>Hd|Z-cndfIj(|Dwweo=bO7Ml@yE6Q* zp{4ExfIEi&CA7Kfp5wG`_%?u{CHB+?u6QmGWPuz5@0Pf4*8)j&=g2z5u2KH@UES?t zpTH7I?I~{@E=xAsffkyoS-?dg+228`29`Z3?>;%T09;CEYO;LrIa7_w@@snn-sF}t jkms(I9C literal 0 HcmV?d00001 diff --git a/res/logos/icons8-xbox-lt-30.png b/res/logos/icons8-xbox-lt-30.png new file mode 100644 index 0000000000000000000000000000000000000000..2509ad8cf2c6c614a7be752cc03c18ae10673542 GIT binary patch literal 390 zcmV;10eSw3P){jP&>g!F-0ncB!tL;2^@l(ofBuR_Jb+*T=+42hcs#aF$JIv z^bG17*w&yK;L8Z@*Qo|xHAY?SY2f_?;57|gP5@rezz@b~2bhRM-GY`e{HE!4E@Ja8 zuns(XW0x}aTitu>9yRb%1iUQsciz|;Fbhn}+?X7@y7AWCYT%UsxL@xwHxse9u7R@& zz;2H!ug0+I=5jeVhI?`*W3w>?J^)Unt^?q$corss&j{GhP5@lez%KcLjqZ`C4b+p& zwdD9}2;7v0VlxFajNf26ZP%N|aFu{u7=JA0wXnM`6+`?mr0a3u2Pi;23z3 kAGlDo3lv9z)9}~)0GWG@h{mQ*A^-pY07*qoM6N<$f(WIiBme*a literal 0 HcmV?d00001 diff --git a/res/logos/icons8-xbox-rt-30.png b/res/logos/icons8-xbox-rt-30.png new file mode 100644 index 0000000000000000000000000000000000000000..77714912926e52059854654d75a65c8b532e12c1 GIT binary patch literal 414 zcmV;P0b%}$P))ScAQ+5R%Ly7S8ZL`X z1#N=Wzd(y@Sy^aMS!mrxa>U8^yYej zDd57+?{%otbm}}Pa2N3H!TrD{uwwfq-~~7ZmVgC2-e>!!Jvs0zVp<+taf(dav3kmz z8UN)~w-mG+`0@&l0GGhAU9Er7WWo1&50}5kNw&ShS@4kpFQyb61#W<0+dt0mjlv`6dVK&fhzFju^Mm&WI{z}fr>%!x0QixQqfh(pk7g(eLhL1wE$5q zZq7WFu)MCa4_Jgx8Yuc>N0yO^>)ve@x1s#!%D)xEtx6?hk$3#{Comy#oxl_D0St?8 zTw>z*%P!%9r(`!ktLpkaS+@bV9`1!p_`$GW3liH7bjy0(z$>|g%Z3lU0DX!x0=yf$ zI~JBPdIY)@CnIOJkM|l{>N$z+09s_d7Fz0phg?)*(Rj_P=DG`MuAFC_#w2c3M(G*o z5#OZe23vFqryb-?iHS14R{nj(-*x?K@^2QeFqCQ5v^=2d<{{9o%jf9j1Q73T|}`E zv9OOn*lI0SuJ{yY6_F%F25w*wcINDE6pI|Va2e)u_MW|GW?+JUhy~yPxB(L2-6FBI zI#3-a;XH5z^nqa{2EZk-SeA4PNCm>5(FJNnNe``qyrh2jjUt^6N|5^Ga_5zT@`hxe zQ;1K;NIHsR#WGpb+w}I`d+QJ0dNZT8Z%SsO5%}s)&!_9&y2~*+KLYjpA>!+ZWX{hH zQ@|teWVu5-Qrig;zeb9Cz_RV#26il80=^=(Nr<>B49bPq^|a;Z;&f*s6}`FY)vSn~ zf6JzY7ttQ0uGMabF{xw2HHtg0=2oofgox|ENW2>&u8P-RUgBQt0C6}GJIE7l#EW0C zl^SlEXA!X`N*)VmvrU!MKex+11l${~5NZWwck*sf5;H){CR6G1EYCkxP_e7+3V62T kHMQIw4tt7aCg88}4dJAiqI60Av;Y7A07*qoM6N<$f*5qZ#{d8T literal 0 HcmV?d00001 From d03e09b34c31a89eb352702dbf3c746098c2db13 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sat, 26 Aug 2023 23:46:46 +0530 Subject: [PATCH 08/31] button icons added image files for button icons --- res/logos/icons8-down-30.png | Bin 0 -> 242 bytes res/logos/icons8-left-30.png | Bin 0 -> 212 bytes res/logos/icons8-right-30.png | Bin 0 -> 209 bytes res/logos/icons8-up-30.png | Bin 0 -> 239 bytes 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 res/logos/icons8-down-30.png create mode 100644 res/logos/icons8-left-30.png create mode 100644 res/logos/icons8-right-30.png create mode 100644 res/logos/icons8-up-30.png diff --git a/res/logos/icons8-down-30.png b/res/logos/icons8-down-30.png new file mode 100644 index 0000000000000000000000000000000000000000..e83151d8b865cc2d4b42f9502846a82b9ce07d92 GIT binary patch literal 242 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP;iN- zi(^Q|oVQmuay1)>v_6by&vb7Wi{Y~K|87^BxiHv~YaQRZ!Yv{pPMIs>CN~uD&rxNu z%iAGvBjM9RPn{1uCJy#nSoI7aOmDqa@!{lI{vVh39@>}uW#z@ETq284x9VM=HeGw8 z-Jgwfnf3O)Tblh~H}lNPTsJ(I?_Jko{PGC<14W1I1ydFU-QnIP^1bWa(dGsJKP*_m n-QUz_$z=Y3bI!70-gkQ#mz3}N`YUJ?$VUvGu6{1-oD!M<_0eDX literal 0 HcmV?d00001 diff --git a/res/logos/icons8-left-30.png b/res/logos/icons8-left-30.png new file mode 100644 index 0000000000000000000000000000000000000000..86edb4e9ddb90fa5cec4c34dd1a94b75599936ff GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP_WI@ z#WAE}&f96$Tnz>StnBvU0+VLHT&e34U9J0-Wh19jhSte-5BT;dU3ECLk5}SYyk6u8I3_+uNnk7413#5JUZ?+o9w=!x+Lh+anwOqNI|(EkF6f*xUKl&MQaa z9<16P!ufQHzQgaGg+aOkS5Jk+3a!fi_)BobxygwVcPtr9Qg&76eCL$~x`@Hk)z4*} HQ$iB}{1Hn_ literal 0 HcmV?d00001 diff --git a/res/logos/icons8-right-30.png b/res/logos/icons8-right-30.png new file mode 100644 index 0000000000000000000000000000000000000000..e7596847976d0626c1d37080219494db57a874e2 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3oCO|{#S9GG!XV7ZFl&wkP_Wt4 z#WAE}&f95*Tn!F9EbKMyi_Q!FU$=AxN7p}PvuT#PUnZ$BN4GUjh~aBes93fm`5c3e zL#pmHYwHUY9Y>?|;)(({?LBGzz(=J1>@Sl7ceR(RV|a|RtMe4+nQU}j?Y;JDuG`O9 zlm5A8&3!c|XwMRjpwH^Xo9%>b4XWn2?y+NXd~lxCqhZ&cWs;8)fX-p?boFyt=akR{ E0B=l5*{nWu%%n Date: Sat, 26 Aug 2023 23:49:33 +0530 Subject: [PATCH 09/31] user defined key maps added the functions and maps required to dynamically change key maps as defined by the user --- src/mainwindow.cpp | 1 + src/preferences.cpp | 260 ++++++++++++++++++- src/preferences.h | 20 ++ src/preferences.ui | 448 +++++++++++++++++++++++++-------- src/settings.cpp | 41 +-- src/settings.h | 22 +- src/settings_key_variables.cpp | 37 ++- src/settings_key_variables.h | 3 +- 8 files changed, 707 insertions(+), 125 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fc3de2c..c8f1786 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,6 +9,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi { load_settings_file(this); load_mouse_setting(); + load_key_maps(); this->p = new Preferences(this); ui->setupUi(this); ui->pushButton->connect(ui->pushButton, &QPushButton::pressed, this, [=] { this->p->show(); }); diff --git a/src/preferences.cpp b/src/preferences.cpp index a7366e9..aba6856 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -4,27 +4,281 @@ #include "ui_preferences.h" #include #include +#include +#include +#include +#include +#include +#include "winuser.h" +#include "windows.h" + Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferences) { ui->setupUi(this); + install_event_filter(); ui->horizontalSlider->adjustSize(); - this->adjustSize(); ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=] { this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); qDebug() << mouse_sensivity << Qt::endl; save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); + change_key_inputs(); //saving key maps }); + ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); + Preferences::set_button_icons(); + ui->formLayout->setHorizontalSpacing(50); + ui->formLayout->setVerticalSpacing(10); ui->horizontalSlider->setValue(mouse_sensivity / 100); + Preferences::load_keys(); +} + +void Preferences::set_button_icons() +{ + QPixmap x; + x.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-x-30.png"); + ui->xbutton->resize(x.size()); + ui->xbutton->setPixmap(x); + QPixmap y; + y.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-y-30.png"); + ui->ybutton->setPixmap(y); + QPixmap a; + a.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-a-30.png"); + ui->abutton->setPixmap(a); + QPixmap b; + b.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-b-30.png"); + ui->bbutton->setPixmap(b); + QPixmap rt; + rt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-rt-30.png"); + ui->Rt->setPixmap(rt); + QPixmap lt; + lt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-lt-30.png"); + ui->Lt->setPixmap(lt); + QPixmap dpad_down; + dpad_down.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-down-30.png"); + ui->ddown->setPixmap(dpad_down); + QPixmap dpad_up; + dpad_up.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-up-30.png"); + ui->dup->setPixmap(dpad_up); + QPixmap dpad_right; + dpad_right.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-right-30.png"); + ui->dright->setPixmap(dpad_right); + QPixmap dpad_left; + dpad_left.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-left-30.png"); + ui->dleft->setPixmap(dpad_left); } int Preferences::change_mouse_sensitivity(int value) { mouse_sensivity = value; - return 1; + return 1; +} + +void Preferences::change_key_inputs() +{ + //change and save key maps + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = this->X; + save_setting(keymaps[setting_keys::keys::X], this->X); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = this->Y; + save_setting(keymaps[setting_keys::keys::Y], this->Y); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = this->A; + save_setting(keymaps[setting_keys::keys::A], this->A); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = this->B; + save_setting(keymaps[setting_keys::keys::B], this->B); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = this->LT; + save_setting(keymaps[setting_keys::keys::LT], this->LT); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = this->RT; + save_setting(keymaps[setting_keys::keys::RT], this->RT); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = this->DDOWN; + save_setting(keymaps[setting_keys::keys::DPADDOWN], this->DDOWN); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = this->DUP; + save_setting(keymaps[setting_keys::keys::DPADUP], this->DUP); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = this->DRIGHT; + save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->DRIGHT); + /*------------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = this->DLEFT; + save_setting(keymaps[setting_keys::keys::DPADLEFT], this->DLEFT); +} + +void Preferences::get_scan_code(WORD vk, char* a, int size) +{ + char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); + if(sc >= 'A' && sc <= 'Z') { + strncpy(a, "", size); + strncpy(a, &sc, 1); + } + else { + strncpy(a, vk_maps[vk], size); + } +} + +void Preferences::load_keys() +{ + char buffer[256]; + this->X = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_X], buffer, 256); + this->ui->xmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->Y = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Y], buffer, 256); + this->ui->ymap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->A = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_A], buffer, 256); + this->ui->amap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->B = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_B], buffer, 256); + this->ui->bmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->RT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_RightThumbstick], buffer, 256); + this->ui->Rtmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->LT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_LeftThumbstick], buffer, 256); + this->ui->Ltmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->DDOWN = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadDown], buffer, 256); + this->ui->ddownmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->DUP = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadUp], buffer, 256); + this->ui->dupmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->DRIGHT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadRight], buffer, 256); + this->ui->drightmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ + this->DLEFT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft], buffer, 256); + this->ui->dleftmap->setText(QString(buffer)); +} + +bool Preferences::eventFilter(QObject *sender, QEvent *event) +{ + if(sender == ui->xmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = (QKeyEvent*)event; + this->X = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->xmap->setText(QString(buffer)); + } + } + else if(sender == ui->ymap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = (QKeyEvent*)event; + this->Y = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->ymap->setText(QString(buffer)); + } + } + else if(sender == ui->amap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->A = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->amap->setText(buffer); + } + } + else if(sender == ui->bmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->B = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->bmap->setText(QString(buffer)); + } + } + else if(sender == ui->Ltmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->LT = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->Ltmap->setText(QString(buffer)); + } + } + else if(sender == ui->Rtmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->RT = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->Rtmap->setText(QString(buffer)); + } + } + else if(sender == ui->dupmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->DUP = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->dupmap->setText(QString(buffer)); + } + } + else if(sender == ui->ddownmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->DDOWN = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->ddownmap->setText(QString(buffer)); + } + } + else if(sender == ui->drightmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->DRIGHT = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->drightmap->setText(QString(buffer)); + } + } + else if(sender == ui->dleftmap) { + if(event->type() == QEvent::KeyRelease) { + QKeyEvent* key_press = static_cast(event); + this->DLEFT = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ui->dleftmap->setText(QString(buffer)); + } + } + return QWidget::eventFilter(sender,event); +} + +void Preferences::keyPressEvent(QKeyEvent *e) +{ + if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Escape) + return; + return QDialog::keyPressEvent(e); +} + +void Preferences::install_event_filter() { + ui->xmap->installEventFilter(this); + ui->ymap->installEventFilter(this); + ui->amap->installEventFilter(this); + ui->bmap->installEventFilter(this); + ui->Ltmap->installEventFilter(this); + ui->Rtmap->installEventFilter(this); + ui->ddownmap->installEventFilter(this); + ui->dupmap->installEventFilter(this); + ui->drightmap->installEventFilter(this); + ui->dleftmap->installEventFilter(this); } Preferences::~Preferences() { - delete ui; + delete ui; } diff --git a/src/preferences.h b/src/preferences.h index 142902c..0cf4b43 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -2,6 +2,7 @@ #define PREFERENCES_H #include +#include namespace Ui { @@ -14,11 +15,30 @@ class Preferences : public QDialog public: explicit Preferences(QWidget *parent = nullptr); + void set_button_icons(); + void load_keys(); ~Preferences(); + protected: + bool eventFilter(QObject* sender, QEvent* event); + void keyPressEvent(QKeyEvent *e); + private: Ui::Preferences *ui; int change_mouse_sensitivity(int value); + void change_key_inputs(); + void get_scan_code(WORD vk, char* a, int size=256); + void install_event_filter(); + UINT X; + UINT Y; + UINT A; + UINT B; + UINT LT; + UINT RT; + UINT DUP; + UINT DDOWN; + UINT DRIGHT; + UINT DLEFT; }; #endif // PREFERENCES_H diff --git a/src/preferences.ui b/src/preferences.ui index 7abd2c0..172e760 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -6,112 +6,362 @@ 0 0 - 400 - 300 + 749 + 544 Preferences - - - - 210 - 240 - 161 - 32 - - - - ArrowCursor - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - 40 - 110 - 281 - 111 - - - - Key Maps - - - - - - 41 - 61 - 281 - 34 - - - - - - - - 16777215 - 16777215 - - - - - true - - - - Pointer Speed - - - 10 - - - - - - - - 140 - 0 - - - - - 140 - 16777215 - - - - 1 - - - 20 - - - 10 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 5 + + + + + + + + 16777215 + 16777215 + + + + + true + + + + Pointer Speed + + + 10 + + + + + + + + 140 + 0 + + + + + 140 + 16777215 + + + + 1 + + + 20 + + + 10 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 5 + + + + + + + + + + 0 + 0 + + + + Key Maps + + + + + 10 + 25 + 191 + 296 + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + TextLabel + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + - - - + + + + + + ArrowCursor + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + diff --git a/src/settings.cpp b/src/settings.cpp index 7d3682f..f7b069f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -7,6 +7,8 @@ QSettings *settings; QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; +void (*load_functions[3])(void) = {load_mouse_setting, load_port_number, load_key_maps}; + void save_setting(QString key, QVariant value) { settings->setValue(key, value); @@ -21,9 +23,14 @@ QVariant load_setting(QString key) return value; } +void set_mouse_sensivity(int sensivity) { + mouse_sensivity = sensivity; +} + + void load_mouse_setting() { - mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; + mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; } void load_settings_file(QObject *parent = nullptr) @@ -31,25 +38,29 @@ void load_settings_file(QObject *parent = nullptr) settings = new QSettings(SETTINGS_FILE, QSettings::Format::IniFormat, parent); } -void set_port_number(int custom_port) { - settings->setValue(server_settings[setting_keys::Port], custom_port); -} - -void load_port_number() { +void load_port_number() // set the port number as user_defined +{ port = settings->value(server_settings[setting_keys::Port]).toInt(); } -void set_key_maps(setting_keys::keys a,WORD value) { - settings->setValue(keymaps[a], value); +void load_key_maps() // set the key mappings to the stored values +{ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = (WORD)settings->value(keymaps[setting_keys::keys::A], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = (WORD)settings->value(keymaps[setting_keys::keys::B], GAMEPAD_BUTTONS[GamepadButtons_B]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = (WORD)settings->value(keymaps[setting_keys::keys::X], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = (WORD)settings->value(keymaps[setting_keys::keys::Y], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::LT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::RT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = (WORD)settings->value(keymaps[setting_keys::keys::DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]).toULongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = (WORD)settings->value(keymaps[setting_keys::keys::DPADUP], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]).toLongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = (WORD)settings->value(keymaps[setting_keys::keys::DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]).toLongLong(); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = (WORD)settings->value(keymaps[setting_keys::keys::DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]).toLongLong(); } -void load_key_maps() { - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = (WORD)settings->value(keymaps[setting_keys::keys::A]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = (WORD)settings->value(keymaps[setting_keys::keys::B]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = (WORD)settings->value(keymaps[setting_keys::keys::X]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = (WORD)settings->value(keymaps[setting_keys::keys::Y]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::LT]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::RT]).toULongLong(); +void load_all_settings() { + for(int i=0;i<3;i++) { + (*load_functions[i])(); + } } diff --git a/src/settings.h b/src/settings.h index f8a886c..f1b324f 100644 --- a/src/settings.h +++ b/src/settings.h @@ -24,17 +24,35 @@ enum keys X, Y, RT, - LT + LT, + DPADDOWN, + DPADUP, + DPADRIGHT, + DPADLEFT }; } // namespace setting_keys extern QSettings *settings; inline QList server_settings = {"port"}; -inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; +//inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; +inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, + {setting_keys::keys::B, "keymaps/B"}, + {setting_keys::keys::X, "keymaps/X"}, + {setting_keys::keys::Y, "keymaps/Y"}, + {setting_keys::keys::RT, "keymaps/RT"}, + {setting_keys::keys::LT, "keymaps/LT"}, + {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, + {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, + {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, + {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}}; + void save_setting(QString key, QVariant value); QVariant load_setting(QString key); void load_mouse_setting(); +void set_mouse_sensivity(); void load_settings_file(QObject *parent); void load_port_number(); +void load_key_maps(); +void load_all_settings(); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 5a3531f..819aa7a 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -2,19 +2,19 @@ int mouse_sensivity = 1000; int port = 7878; -std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, +std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, {GamepadButtons::GamepadButtons_View, VK_TAB}, {GamepadButtons::GamepadButtons_A, VK_RETURN}, - {GamepadButtons::GamepadButtons_B, VK_ESCAPE}, + {GamepadButtons::GamepadButtons_B, 'B'}, {GamepadButtons::GamepadButtons_X, VK_SHIFT}, {GamepadButtons::GamepadButtons_Y, VK_CONTROL}, {GamepadButtons::GamepadButtons_DPadUp, VK_UP}, {GamepadButtons::GamepadButtons_DPadDown, VK_DOWN}, {GamepadButtons::GamepadButtons_DPadLeft, VK_LEFT}, {GamepadButtons::GamepadButtons_DPadRight, VK_RIGHT}, - {GamepadButtons::GamepadButtons_LeftShoulder, 'E'}, - {GamepadButtons::GamepadButtons_RightShoulder, VK_SPACE}, - {GamepadButtons::GamepadButtons_LeftThumbstick, VK_PRIOR}, +// {GamepadButtons::GamepadButtons_LeftShoulder, 'E'}, +// {GamepadButtons::GamepadButtons_RightShoulder, VK_SPACE}, + {GamepadButtons::GamepadButtons_LeftThumbstick, VK_LBUTTON}, {GamepadButtons::GamepadButtons_RightThumbstick, VK_NEXT}}; std::map THUMBSTICK_KEYS = { @@ -22,3 +22,30 @@ std::map THUMBSTICK_KEYS = { {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; + +std::map vk_maps = { + {VK_LBUTTON, "LMButton"}, + {VK_RBUTTON, "RMButton"}, + {VK_MBUTTON, "MMButton"}, + {VK_BACK, "BACKSPACE"}, + {VK_TAB, "TAB"}, + {VK_RETURN, "ENTER"}, + {VK_SHIFT, "SHIFT"}, + {VK_CONTROL, "CTRL"}, + {VK_CAPITAL, "CAPITAL"}, + {VK_ESCAPE, "ESCAPE"}, + {VK_SPACE, "SPACE"}, + {VK_PRIOR, "PageUP"}, + {VK_NEXT, "PageDOWN"}, + {VK_END, "END"}, + {VK_HOME, "HOME"}, + {VK_LEFT, "LEFT"}, + {VK_UP, "UP"}, + {VK_RIGHT, "RIGHT"}, + {VK_DOWN, "DOWN"}, + {VK_INSERT, "INS"}, + {VK_DELETE, "DEL"}, + {VK_OEM_PERIOD, "."}, + {VK_OEM_COMMA, ","}, + {VK_OEM_MINUS, "-"} +}; diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index 9f7f7d1..bf02ff1 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -9,7 +9,7 @@ extern int mouse_sensivity; extern int port; -extern std::map GAMEPAD_BUTTONS; +extern std::map GAMEPAD_BUTTONS; enum Thumbstick { @@ -24,3 +24,4 @@ enum Thumbstick }; extern std::map THUMBSTICK_KEYS; +extern std::map vk_maps; From 11ea776b5bf9ae0ea2b68773d4423520f964a188 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:11:14 +0530 Subject: [PATCH 10/31] fixing bugs and adding resources fixing the bug that occurs when mapping to numbers, adding the icon files qt resource --- res/icons.qrc | 10 ++++++++++ src/preferences.cpp | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/res/icons.qrc b/res/icons.qrc index fc988ad..dc4b696 100644 --- a/res/icons.qrc +++ b/res/icons.qrc @@ -4,5 +4,15 @@ logos/GamepadIcon.svg logos/GamepadIcon_transparent.png logos/SquareIcon.png + logos/icons8-down-30.png + logos/icons8-left-30.png + logos/icons8-right-30.png + logos/icons8-up-30.png + logos/icons8-xbox-a-30.png + logos/icons8-xbox-b-30.png + logos/icons8-xbox-lt-30.png + logos/icons8-xbox-rt-30.png + logos/icons8-xbox-x-30.png + logos/icons8-xbox-y-30.png diff --git a/src/preferences.cpp b/src/preferences.cpp index aba6856..b9f4679 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -35,35 +35,34 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen void Preferences::set_button_icons() { QPixmap x; - x.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-x-30.png"); - ui->xbutton->resize(x.size()); + x.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-x-30.png"); // https://icons8.com/icon/80114/xbox-x ui->xbutton->setPixmap(x); QPixmap y; - y.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-y-30.png"); + y.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-y-30.png"); // https://icons8.com/icon/80111/xbox-y ui->ybutton->setPixmap(y); QPixmap a; - a.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-a-30.png"); + a.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-a-30.png"); // https://icons8.com/icon/80108/xbox-a ui->abutton->setPixmap(a); QPixmap b; - b.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-b-30.png"); + b.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-b-30.png"); // https://icons8.com/icon/80102/xbox-b ui->bbutton->setPixmap(b); QPixmap rt; - rt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-rt-30.png"); + rt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-rt-30.png"); // https://icons8.com/icon/80116/xbox-rt ui->Rt->setPixmap(rt); QPixmap lt; - lt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-lt-30.png"); + lt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-lt-30.png"); // https://icons8.com/icon/80107/xbox-lt ui->Lt->setPixmap(lt); QPixmap dpad_down; - dpad_down.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-down-30.png"); + dpad_down.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-down-30.png"); // https://icons8.com/ ui->ddown->setPixmap(dpad_down); QPixmap dpad_up; - dpad_up.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-up-30.png"); + dpad_up.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-up-30.png"); // https://icons8.com/icon/100000/up ui->dup->setPixmap(dpad_up); QPixmap dpad_right; - dpad_right.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-right-30.png"); + dpad_right.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-right-30.png"); // https://icons8.com/icon/98968/right ui->dright->setPixmap(dpad_right); QPixmap dpad_left; - dpad_left.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-left-30.png"); + dpad_left.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-left-30.png"); // https://icons8.com/icon/98961/left ui->dleft->setPixmap(dpad_left); } @@ -110,7 +109,7 @@ void Preferences::change_key_inputs() void Preferences::get_scan_code(WORD vk, char* a, int size) { char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); - if(sc >= 'A' && sc <= 'Z') { + if(sc >= '0' && sc <= 'Z') { strncpy(a, "", size); strncpy(a, &sc, 1); } From a2509f19d05a2bcb16ba4ada3eaa2c2a0b12890a Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:41:54 +0530 Subject: [PATCH 11/31] add tracking for mouse_press adding the mouse press filter to map the keys to mouse buttons --- src/preferences.cpp | 252 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 251 insertions(+), 1 deletion(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index b9f4679..309d4cb 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include "winuser.h" #include "windows.h" @@ -172,6 +172,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->xmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->X = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->X = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->X = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->xmap->setText(QString(buffer)); + } } else if(sender == ui->ymap) { if(event->type() == QEvent::KeyRelease) { @@ -181,6 +206,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->ymap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->Y = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->Y = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->Y = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->ymap->setText(QString(buffer)); + } } else if(sender == ui->amap) { if(event->type() == QEvent::KeyRelease) { @@ -190,6 +240,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->amap->setText(buffer); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->A = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->A = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->A = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->amap->setText(QString(buffer)); + } } else if(sender == ui->bmap) { if(event->type() == QEvent::KeyRelease) { @@ -199,6 +274,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->bmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->B = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->B = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->B = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->bmap->setText(QString(buffer)); + } } else if(sender == ui->Ltmap) { if(event->type() == QEvent::KeyRelease) { @@ -208,6 +308,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->Ltmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->LT = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->LT = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->LT = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->Ltmap->setText(QString(buffer)); + } } else if(sender == ui->Rtmap) { if(event->type() == QEvent::KeyRelease) { @@ -217,6 +342,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->Rtmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->RT = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->RT = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->RT = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->Rtmap->setText(QString(buffer)); + } } else if(sender == ui->dupmap) { if(event->type() == QEvent::KeyRelease) { @@ -226,6 +376,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->dupmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->DUP = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->DUP = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->DUP = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->dupmap->setText(QString(buffer)); + } } else if(sender == ui->ddownmap) { if(event->type() == QEvent::KeyRelease) { @@ -235,6 +410,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->ddownmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->DDOWN = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->DDOWN = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->DDOWN = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->ddownmap->setText(QString(buffer)); + } } else if(sender == ui->drightmap) { if(event->type() == QEvent::KeyRelease) { @@ -244,6 +444,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->drightmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->DRIGHT = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->DRIGHT = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->DRIGHT = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->drightmap->setText(QString(buffer)); + } } else if(sender == ui->dleftmap) { if(event->type() == QEvent::KeyRelease) { @@ -253,6 +478,31 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->dleftmap->setText(QString(buffer)); } + else if(event->type() == QEvent::MouseButtonRelease) { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->DLEFT = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->DLEFT = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->DLEFT = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + valid = false; + } + if(valid) + ui->dleftmap->setText(QString(buffer)); + } } return QWidget::eventFilter(sender,event); } From 1e8f6529ab6bb2c1f0a942a88683fdcc2491e6c6 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:39:25 +0530 Subject: [PATCH 12/31] Moved resource files --- res/icons.qrc | 20 ++++++++++---------- res/{logos => icons}/icons8-down-30.png | Bin res/{logos => icons}/icons8-left-30.png | Bin res/{logos => icons}/icons8-right-30.png | Bin res/{logos => icons}/icons8-up-30.png | Bin res/{logos => icons}/icons8-xbox-a-30.png | Bin res/{logos => icons}/icons8-xbox-b-30.png | Bin res/{logos => icons}/icons8-xbox-lt-30.png | Bin res/{logos => icons}/icons8-xbox-rt-30.png | Bin res/{logos => icons}/icons8-xbox-x-30.png | Bin res/{logos => icons}/icons8-xbox-y-30.png | Bin 11 files changed, 10 insertions(+), 10 deletions(-) rename res/{logos => icons}/icons8-down-30.png (100%) rename res/{logos => icons}/icons8-left-30.png (100%) rename res/{logos => icons}/icons8-right-30.png (100%) rename res/{logos => icons}/icons8-up-30.png (100%) rename res/{logos => icons}/icons8-xbox-a-30.png (100%) rename res/{logos => icons}/icons8-xbox-b-30.png (100%) rename res/{logos => icons}/icons8-xbox-lt-30.png (100%) rename res/{logos => icons}/icons8-xbox-rt-30.png (100%) rename res/{logos => icons}/icons8-xbox-x-30.png (100%) rename res/{logos => icons}/icons8-xbox-y-30.png (100%) diff --git a/res/icons.qrc b/res/icons.qrc index dc4b696..ab095a4 100644 --- a/res/icons.qrc +++ b/res/icons.qrc @@ -4,15 +4,15 @@ logos/GamepadIcon.svg logos/GamepadIcon_transparent.png logos/SquareIcon.png - logos/icons8-down-30.png - logos/icons8-left-30.png - logos/icons8-right-30.png - logos/icons8-up-30.png - logos/icons8-xbox-a-30.png - logos/icons8-xbox-b-30.png - logos/icons8-xbox-lt-30.png - logos/icons8-xbox-rt-30.png - logos/icons8-xbox-x-30.png - logos/icons8-xbox-y-30.png + icons/icons8-down-30.png + icons/icons8-left-30.png + icons/icons8-right-30.png + icons/icons8-up-30.png + icons/icons8-xbox-a-30.png + icons/icons8-xbox-b-30.png + icons/icons8-xbox-lt-30.png + icons/icons8-xbox-rt-30.png + icons/icons8-xbox-x-30.png + icons/icons8-xbox-y-30.png diff --git a/res/logos/icons8-down-30.png b/res/icons/icons8-down-30.png similarity index 100% rename from res/logos/icons8-down-30.png rename to res/icons/icons8-down-30.png diff --git a/res/logos/icons8-left-30.png b/res/icons/icons8-left-30.png similarity index 100% rename from res/logos/icons8-left-30.png rename to res/icons/icons8-left-30.png diff --git a/res/logos/icons8-right-30.png b/res/icons/icons8-right-30.png similarity index 100% rename from res/logos/icons8-right-30.png rename to res/icons/icons8-right-30.png diff --git a/res/logos/icons8-up-30.png b/res/icons/icons8-up-30.png similarity index 100% rename from res/logos/icons8-up-30.png rename to res/icons/icons8-up-30.png diff --git a/res/logos/icons8-xbox-a-30.png b/res/icons/icons8-xbox-a-30.png similarity index 100% rename from res/logos/icons8-xbox-a-30.png rename to res/icons/icons8-xbox-a-30.png diff --git a/res/logos/icons8-xbox-b-30.png b/res/icons/icons8-xbox-b-30.png similarity index 100% rename from res/logos/icons8-xbox-b-30.png rename to res/icons/icons8-xbox-b-30.png diff --git a/res/logos/icons8-xbox-lt-30.png b/res/icons/icons8-xbox-lt-30.png similarity index 100% rename from res/logos/icons8-xbox-lt-30.png rename to res/icons/icons8-xbox-lt-30.png diff --git a/res/logos/icons8-xbox-rt-30.png b/res/icons/icons8-xbox-rt-30.png similarity index 100% rename from res/logos/icons8-xbox-rt-30.png rename to res/icons/icons8-xbox-rt-30.png diff --git a/res/logos/icons8-xbox-x-30.png b/res/icons/icons8-xbox-x-30.png similarity index 100% rename from res/logos/icons8-xbox-x-30.png rename to res/icons/icons8-xbox-x-30.png diff --git a/res/logos/icons8-xbox-y-30.png b/res/icons/icons8-xbox-y-30.png similarity index 100% rename from res/logos/icons8-xbox-y-30.png rename to res/icons/icons8-xbox-y-30.png From c393a5f4ca82b9eae8fa79657f90c7452c635c3e Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:03:06 +0530 Subject: [PATCH 13/31] Use resources instead of absolute paths --- src/preferences.cpp | 35 --------------------------------- src/preferences.h | 3 +-- src/preferences.ui | 48 +++++++++++++++++++++++---------------------- 3 files changed, 26 insertions(+), 60 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index 309d4cb..baec824 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -25,47 +25,12 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen change_key_inputs(); //saving key maps }); ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); - Preferences::set_button_icons(); ui->formLayout->setHorizontalSpacing(50); ui->formLayout->setVerticalSpacing(10); ui->horizontalSlider->setValue(mouse_sensivity / 100); Preferences::load_keys(); } -void Preferences::set_button_icons() -{ - QPixmap x; - x.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-x-30.png"); // https://icons8.com/icon/80114/xbox-x - ui->xbutton->setPixmap(x); - QPixmap y; - y.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-y-30.png"); // https://icons8.com/icon/80111/xbox-y - ui->ybutton->setPixmap(y); - QPixmap a; - a.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-a-30.png"); // https://icons8.com/icon/80108/xbox-a - ui->abutton->setPixmap(a); - QPixmap b; - b.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-b-30.png"); // https://icons8.com/icon/80102/xbox-b - ui->bbutton->setPixmap(b); - QPixmap rt; - rt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-rt-30.png"); // https://icons8.com/icon/80116/xbox-rt - ui->Rt->setPixmap(rt); - QPixmap lt; - lt.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-xbox-lt-30.png"); // https://icons8.com/icon/80107/xbox-lt - ui->Lt->setPixmap(lt); - QPixmap dpad_down; - dpad_down.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-down-30.png"); // https://icons8.com/ - ui->ddown->setPixmap(dpad_down); - QPixmap dpad_up; - dpad_up.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-up-30.png"); // https://icons8.com/icon/100000/up - ui->dup->setPixmap(dpad_up); - QPixmap dpad_right; - dpad_right.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-right-30.png"); // https://icons8.com/icon/98968/right - ui->dright->setPixmap(dpad_right); - QPixmap dpad_left; - dpad_left.load("C:\\Users\\saisi\\Memory_card\\VirtualGamePad-PC\\res\\logos\\icons8-left-30.png"); // https://icons8.com/icon/98961/left - ui->dleft->setPixmap(dpad_left); -} - int Preferences::change_mouse_sensitivity(int value) { mouse_sensivity = value; diff --git a/src/preferences.h b/src/preferences.h index 0cf4b43..a8bca04 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -14,8 +14,7 @@ class Preferences : public QDialog Q_OBJECT public: - explicit Preferences(QWidget *parent = nullptr); - void set_button_icons(); + explicit Preferences(QWidget *parent = nullptr); void load_keys(); ~Preferences(); diff --git a/src/preferences.ui b/src/preferences.ui index 172e760..0a7283f 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -89,15 +89,15 @@ 10 25 - 191 - 296 + 238 + 356 - - TextLabel + + :/icons/icons8-xbox-x-30.png @@ -121,8 +121,8 @@ - - TextLabel + + :/icons/icons8-xbox-y-30.png @@ -146,8 +146,8 @@ - - TextLabel + + :/icons/icons8-xbox-a-30.png @@ -171,8 +171,8 @@ - - TextLabel + + :/icons/icons8-xbox-b-30.png @@ -196,8 +196,8 @@ - - TextLabel + + :/icons/icons8-xbox-rt-30.png @@ -221,8 +221,8 @@ - - TextLabel + + :/icons/icons8-xbox-lt-30.png @@ -246,8 +246,8 @@ - - TextLabel + + :/icons/icons8-down-30.png @@ -271,8 +271,8 @@ - - TextLabel + + :/icons/icons8-up-30.png @@ -296,8 +296,8 @@ - - TextLabel + + :/icons/icons8-right-30.png @@ -321,8 +321,8 @@ - - TextLabel + + :/icons/icons8-left-30.png @@ -363,7 +363,9 @@ - + + + buttonBox From 3cda9c730aca2d4c9f90ccb7b2e37b1182bc592f Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:38:14 +0530 Subject: [PATCH 14/31] Update src/main.cpp Co-authored-by: kitswas <90329875+kitswas@users.noreply.github.com> --- src/main.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f192b48..bc2c6c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,4 @@ -#include "settings.h" #include -#include #include #include "mainwindow.hpp" From 6da54fc03beb2dfb3102ba2bddd1ce0d8b331ebd Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:38:36 +0530 Subject: [PATCH 15/31] Update CMakeLists.txt Co-authored-by: kitswas <90329875+kitswas@users.noreply.github.com> --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bdadabf..fdd39e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,8 +19,7 @@ set(THIRD_PARTY_LIB_SOURCES third-party-libs/QR-Code-generator/cpp/qrcodegen.hpp ) -add_library(QR_Code_Generator SHARED ${THIRD_PARTY_LIB_SOURCES} -) +add_library(QR_Code_Generator SHARED ${THIRD_PARTY_LIB_SOURCES}) set(PROJECT_SOURCES src/main.cpp From 63366242a92a5662302f4a3797e4fea035e4e959 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Wed, 30 Aug 2023 19:48:26 +0530 Subject: [PATCH 16/31] fixing the suggested changes fixing the broken include guard, removed the redundant functions, removed the qt::endl, fixed the typo in config file name --- src/mainwindow.cpp | 2 +- src/mainwindow.ui | 4 ++-- src/settings.cpp | 11 +++-------- src/settings.h | 4 ++-- src/settings_key_variables.cpp | 3 ++- src/settings_key_variables.h | 3 ++- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c8f1786..1baed30 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -12,7 +12,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi load_key_maps(); this->p = new Preferences(this); ui->setupUi(this); - ui->pushButton->connect(ui->pushButton, &QPushButton::pressed, this, [=] { this->p->show(); }); + ui->settingsButton->connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); } MainWindow::~MainWindow() diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7c714cd..b006ff4 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -30,7 +30,7 @@ - + Preferences @@ -44,7 +44,7 @@ 0 0 800 - 17 + 21 diff --git a/src/settings.cpp b/src/settings.cpp index f7b069f..aaec453 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2,7 +2,7 @@ #include "settings_key_variables.h" #include -QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.Ini"); +QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); QSettings *settings; QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; @@ -13,8 +13,8 @@ void save_setting(QString key, QVariant value) { settings->setValue(key, value); settings->sync(); - qDebug() << settings->value(key).toString() << Qt::endl; - qDebug() << settings->fileName() << Qt::endl; + qDebug() << settings->value(key).toString(); + qDebug() << settings->fileName(); } QVariant load_setting(QString key) @@ -23,11 +23,6 @@ QVariant load_setting(QString key) return value; } -void set_mouse_sensivity(int sensivity) { - mouse_sensivity = sensivity; -} - - void load_mouse_setting() { mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; diff --git a/src/settings.h b/src/settings.h index f1b324f..76c23fe 100644 --- a/src/settings.h +++ b/src/settings.h @@ -1,7 +1,5 @@ #ifndef SETTINGS_H #define SETTINGS_H - -#endif // SETTINGS_H #include #include @@ -56,3 +54,5 @@ void load_settings_file(QObject *parent); void load_port_number(); void load_key_maps(); void load_all_settings(); + +#endif // SETTINGS_H diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 819aa7a..0c4b68f 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -47,5 +47,6 @@ std::map vk_maps = { {VK_DELETE, "DEL"}, {VK_OEM_PERIOD, "."}, {VK_OEM_COMMA, ","}, - {VK_OEM_MINUS, "-"} + {VK_OEM_MINUS, "-"}, + {VK_OEM_PLUS, "+"} }; diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index bf02ff1..33060ff 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -2,7 +2,6 @@ #ifndef SETTINGS_KEY_VARIABLES_H #define SETTINGS_KEY_VARIABLES_H #include -#endif // SETTINGS_KEY_VARIABLES_H #include #include "../VGP_Data_Exchange/C/GameButtons.h" @@ -25,3 +24,5 @@ enum Thumbstick extern std::map THUMBSTICK_KEYS; extern std::map vk_maps; + +#endif // SETTINGS_KEY_VARIABLES_H From c64b9d1f202e83874d5d485418beb42fc69bb756 Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Thu, 31 Aug 2023 00:09:23 +0530 Subject: [PATCH 17/31] Updated the preferences UI --- src/preferences.ui | 543 ++++++++++++++++++++++----------------------- 1 file changed, 262 insertions(+), 281 deletions(-) diff --git a/src/preferences.ui b/src/preferences.ui index 0a7283f..bd6eb83 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -18,11 +18,11 @@ - - - 16777215 - 16777215 - + + + 1 + 0 + @@ -32,24 +32,15 @@ Pointer Speed - - 10 - - - - 140 - 0 - - - - - 140 - 16777215 - + + + 2 + 0 + 1 @@ -84,268 +75,258 @@ Key Maps - - - - 10 - 25 - 238 - 356 - - - - - - - :/icons/icons8-xbox-x-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-xbox-y-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-xbox-a-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-xbox-b-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-xbox-rt-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-xbox-lt-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-down-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-up-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-right-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - - - :/icons/icons8-left-30.png - - - - - - - - 0 - 0 - - - - - true - - - - true - - - - - + + + + + :/icons/icons8-xbox-x-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-xbox-y-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-xbox-a-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-xbox-b-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-xbox-rt-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-xbox-lt-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-down-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-up-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-right-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + + + + :/icons/icons8-left-30.png + + + + + + + + 0 + 0 + + + + + true + + + + true + + + + From d07915271dadd471f1e3d4e86a00da908dd24455 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:00:51 +0530 Subject: [PATCH 18/31] added documentation described all the functions, their parameters and what the functions return. --- src/preferences.cpp | 75 ++++++++++++++++++++++++++-------- src/settings.cpp | 42 ++++++++++++++++++- src/settings.h | 6 ++- src/settings_key_variables.cpp | 17 +++++++- 4 files changed, 119 insertions(+), 21 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index baec824..519af56 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -18,11 +18,11 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen ui->setupUi(this); install_event_filter(); ui->horizontalSlider->adjustSize(); - ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=] { + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=] { // running the functions to change and save the new settings if the user presses ok this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); - qDebug() << mouse_sensivity << Qt::endl; - save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); - change_key_inputs(); //saving key maps + qDebug() << mouse_sensivity; + save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); //saving the new mouse sensivity + change_key_inputs(); //changing and saving key maps }); ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); ui->formLayout->setHorizontalSpacing(50); @@ -37,6 +37,12 @@ int Preferences::change_mouse_sensitivity(int value) return 1; } +/** + * @brief Preferences::change_key_inputs + * this changes the keyboard maps and saves those changes in the config file. + * this function is executed if the user presses ok button. + */ + void Preferences::change_key_inputs() { //change and save key maps @@ -71,6 +77,16 @@ void Preferences::change_key_inputs() save_setting(keymaps[setting_keys::keys::DPADLEFT], this->DLEFT); } +/** + * @brief Preferences::get_scan_code + * get the name of the of corrosponding key or virutal key code. + * @param vk + * the virtual key code of the key you want to get. + * @param a + * the buffer to store the name of the key. + * @param size + * size of the buffer in which the name is stored to ensure memory safety + */ void Preferences::get_scan_code(WORD vk, char* a, int size) { char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); @@ -83,6 +99,11 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) } } +/** + * @brief Preferences::load_keys + * displays the key to which each button is mapped to. + * saves the initial key maps in variables that can be changed later if user wants to. + */ void Preferences::load_keys() { char buffer[256]; @@ -127,17 +148,29 @@ void Preferences::load_keys() this->ui->dleftmap->setText(QString(buffer)); } +/** + * @brief Preferences::eventFilter + * the event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change the button-key maps. + * checks which object is sending the event and type of event. + * if event is a keyboard or mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the change in a temporary variable. + * @param sender + * to get the address of the object that is triggering the event. + * @param event + * to capture the event that was triggered. + * @return [bool] + * returns true if event is handled else false. + */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { if(sender == ui->xmap) { - if(event->type() == QEvent::KeyRelease) { + if(event->type() == QEvent::KeyRelease && ui->xmap->text() == "") { QKeyEvent* key_press = (QKeyEvent*)event; this->X = key_press->nativeVirtualKey(); char buffer[256]; get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ui->xmap->setText(QString(buffer)); } - else if(event->type() == QEvent::MouseButtonRelease) { + else if(event->type() == QEvent::MouseButtonPress && ui->xmap->text() == "") { QMouseEvent* mouse_press = static_cast(event); char buffer[256]; bool valid = true; @@ -156,7 +189,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -190,7 +223,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -224,7 +257,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -258,7 +291,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -292,7 +325,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -326,7 +359,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -360,7 +393,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -394,7 +427,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -428,7 +461,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -462,7 +495,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) get_scan_code(VK_MBUTTON, buffer, 256); break; default: - qDebug() << "Some Error Occured No Legal Mouse Button found" << Qt::endl; + qDebug() << "Some Error Occured No Legal Mouse Button found"; valid = false; } if(valid) @@ -472,6 +505,12 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) return QWidget::eventFilter(sender,event); } +/** + * @brief Preferences::keyPressEvent + * make the Qdialog box ignores the enter key and escape key presses when the focus is on button map + * @param e + * capture the key_press event + */ void Preferences::keyPressEvent(QKeyEvent *e) { if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Escape) @@ -479,6 +518,10 @@ void Preferences::keyPressEvent(QKeyEvent *e) return QDialog::keyPressEvent(e); } +/** + * @brief Preferences::install_event_filter + * install the above event filter on all the button maps to capture the key presses when they have the focus. + */ void Preferences::install_event_filter() { ui->xmap->installEventFilter(this); ui->ymap->installEventFilter(this); diff --git a/src/settings.cpp b/src/settings.cpp index aaec453..54c0d2f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -2,13 +2,21 @@ #include "settings_key_variables.h" #include -QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); +QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini QSettings *settings; QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; -void (*load_functions[3])(void) = {load_mouse_setting, load_port_number, load_key_maps}; +void (*load_functions[3])(void) = {load_mouse_setting, load_port_number, load_key_maps}; // an array of pointer to functions that needs to run on startup to load settings. +/** + * @brief save_setting + * save a setting to the settings file + * @param key + * the name of the setting in string format if you want to group settings seperate the head group using + * @param value + * the value of the settings can be of any data type string, int, char, float, e.t.c. + */ void save_setting(QString key, QVariant value) { settings->setValue(key, value); @@ -17,27 +25,53 @@ void save_setting(QString key, QVariant value) qDebug() << settings->fileName(); } +/** + * @brief load_setting + * get the value of a setting. + * @param key + * the fullname including the groups of the setting in string format + * @return + * returns the value as QVariant can be converted into almost all data types. + */ QVariant load_setting(QString key) { QVariant value = settings->value(key); return value; } +/** + * @brief load_mouse_setting + * loads and sets the mouse sensivity. + */ void load_mouse_setting() { mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; } +/** + * @brief load_settings_file + * loads the settings file for the current application. + * @param parent + * the parent object either a widget or Qt Application e.t.c + */ void load_settings_file(QObject *parent = nullptr) { settings = new QSettings(SETTINGS_FILE, QSettings::Format::IniFormat, parent); } +/** + * @brief load_port_number + * load and set the port number + */ void load_port_number() // set the port number as user_defined { port = settings->value(server_settings[setting_keys::Port]).toInt(); } +/** + * @brief load_key_maps + * load the key maps from the settings file. + */ void load_key_maps() // set the key mappings to the stored values { GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = (WORD)settings->value(keymaps[setting_keys::keys::A], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]).toULongLong(); @@ -52,6 +86,10 @@ void load_key_maps() // set the key mappings to the stored values GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = (WORD)settings->value(keymaps[setting_keys::keys::DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]).toLongLong(); } +/** + * @brief load_all_settings + * run the functions using the function array to load all the necessary settings. + */ void load_all_settings() { for(int i=0;i<3;i++) { (*load_functions[i])(); diff --git a/src/settings.h b/src/settings.h index 76c23fe..3852681 100644 --- a/src/settings.h +++ b/src/settings.h @@ -5,7 +5,7 @@ extern QString SETTINGS_FILE; -namespace setting_keys +namespace setting_keys // a name space to maintain the key names. { enum server_keys @@ -34,6 +34,10 @@ enum keys extern QSettings *settings; inline QList server_settings = {"port"}; //inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; +/** + * @brief keymaps + * a Qmap to map the keys in namespace to corresponding settings name in string format. + */ inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, {setting_keys::keys::B, "keymaps/B"}, {setting_keys::keys::X, "keymaps/X"}, diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 0c4b68f..fe55c8f 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -1,7 +1,12 @@ #include "settings_key_variables.h" -int mouse_sensivity = 1000; -int port = 7878; +int mouse_sensivity = 1000; // the mouse_sensivity or the cursor speed. +int port = 7878; // the port on which the server runs on. + +/** + * @brief GAMEPAD_BUTTONS + * a map for the gamepad button and the corresponding input. + */ std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, {GamepadButtons::GamepadButtons_View, VK_TAB}, {GamepadButtons::GamepadButtons_A, VK_RETURN}, @@ -17,12 +22,20 @@ std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButton {GamepadButtons::GamepadButtons_LeftThumbstick, VK_LBUTTON}, {GamepadButtons::GamepadButtons_RightThumbstick, VK_NEXT}}; +/** + * @brief THUMBSTICK_KEYS + * maps the joystick movements. + */ std::map THUMBSTICK_KEYS = { {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; +/** + * @brief vk_maps + * a std::map to map the virtual key codes to corresponding key names + */ std::map vk_maps = { {VK_LBUTTON, "LMButton"}, {VK_RBUTTON, "RMButton"}, From 9a29227d9b90c4a416e8f70bc80484d061625a6a Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:09:01 +0530 Subject: [PATCH 19/31] fixing key sizes --- src/preferences.ui | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/preferences.ui b/src/preferences.ui index bd6eb83..e72bfc7 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -16,10 +16,13 @@ + + QLayout::SetMaximumSize + - + 1 0 @@ -37,7 +40,7 @@ - + 2 0 @@ -86,7 +89,7 @@ - + 0 0 @@ -111,7 +114,7 @@ - + 0 0 @@ -136,7 +139,7 @@ - + 0 0 @@ -161,7 +164,7 @@ - + 0 0 @@ -186,7 +189,7 @@ - + 0 0 @@ -211,7 +214,7 @@ - + 0 0 @@ -236,7 +239,7 @@ - + 0 0 @@ -261,7 +264,7 @@ - + 0 0 @@ -286,7 +289,7 @@ - + 0 0 @@ -311,7 +314,7 @@ - + 0 0 From e328c12217185925b8f978ed9c713691d5bf6b89 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 1 Sep 2023 22:12:35 +0530 Subject: [PATCH 20/31] Revert "fixing key sizes" This reverts commit 9a29227d9b90c4a416e8f70bc80484d061625a6a. --- src/preferences.ui | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/preferences.ui b/src/preferences.ui index e72bfc7..bd6eb83 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -16,13 +16,10 @@ - - QLayout::SetMaximumSize - - + 1 0 @@ -40,7 +37,7 @@ - + 2 0 @@ -89,7 +86,7 @@ - + 0 0 @@ -114,7 +111,7 @@ - + 0 0 @@ -139,7 +136,7 @@ - + 0 0 @@ -164,7 +161,7 @@ - + 0 0 @@ -189,7 +186,7 @@ - + 0 0 @@ -214,7 +211,7 @@ - + 0 0 @@ -239,7 +236,7 @@ - + 0 0 @@ -264,7 +261,7 @@ - + 0 0 @@ -289,7 +286,7 @@ - + 0 0 @@ -314,7 +311,7 @@ - + 0 0 From 1ada43d293ba4bb0df63a35efaddd52759b5c620 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 1 Sep 2023 22:35:43 +0530 Subject: [PATCH 21/31] changes to documentation and fixing sizes --- src/preferences.cpp | 13 +++++++++---- src/preferences.h | 2 +- src/preferences.ui | 28 +++++++++++++++++++++++++--- src/settings.cpp | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index 519af56..d4c77e1 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -31,10 +31,15 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen Preferences::load_keys(); } -int Preferences::change_mouse_sensitivity(int value) +/** + * @brief Preferences::change_mouse_sensitivity + * changes the mouse sensivity or the cursor speed + * @param value + * the amount of mouse sensivity you want to set. + */ +void Preferences::change_mouse_sensitivity(int value) { mouse_sensivity = value; - return 1; } /** @@ -79,7 +84,7 @@ void Preferences::change_key_inputs() /** * @brief Preferences::get_scan_code - * get the name of the of corrosponding key or virutal key code. + * gets the name of the of corrosponding key or virutal key code. * @param vk * the virtual key code of the key you want to get. * @param a @@ -158,7 +163,7 @@ void Preferences::load_keys() * @param event * to capture the event that was triggered. * @return [bool] - * returns true if event is handled else false. + * true if event is handled else false. */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { diff --git a/src/preferences.h b/src/preferences.h index a8bca04..705acf4 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -24,7 +24,7 @@ class Preferences : public QDialog private: Ui::Preferences *ui; - int change_mouse_sensitivity(int value); + void change_mouse_sensitivity(int value); void change_key_inputs(); void get_scan_code(WORD vk, char* a, int size=256); void install_event_filter(); diff --git a/src/preferences.ui b/src/preferences.ui index bd6eb83..407542a 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -6,8 +6,8 @@ 0 0 - 749 - 544 + 400 + 473 @@ -32,13 +32,16 @@ Pointer Speed + + Qt::AlignCenter + - 2 + 1 0 @@ -72,9 +75,18 @@ 0 + + + 10 + true + + Key Maps + + Qt::AlignCenter + @@ -93,6 +105,7 @@ + 10 true @@ -118,6 +131,7 @@ + 10 true @@ -143,6 +157,7 @@ + 10 true @@ -168,6 +183,7 @@ + 10 true @@ -193,6 +209,7 @@ + 10 true @@ -218,6 +235,7 @@ + 10 true @@ -243,6 +261,7 @@ + 10 true @@ -268,6 +287,7 @@ + 10 true @@ -293,6 +313,7 @@ + 10 true @@ -318,6 +339,7 @@ + 10 true diff --git a/src/settings.cpp b/src/settings.cpp index 54c0d2f..ef69a0c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -31,7 +31,7 @@ void save_setting(QString key, QVariant value) * @param key * the fullname including the groups of the setting in string format * @return - * returns the value as QVariant can be converted into almost all data types. + * the setting as QVariant can be converted into almost all data types. */ QVariant load_setting(QString key) { From 750c2b8276f1a0680929f8c1fc9ef6e3ad5c301d Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Mon, 4 Sep 2023 20:40:41 +0530 Subject: [PATCH 22/31] removing unccessary code decreasing the length of code using for loops and iterators. and removing excess if statements and variables, changing the order of key maps. --- src/preferences.cpp | 449 +++++++------------------------------------- src/preferences.h | 11 +- src/preferences.ui | 12 +- 3 files changed, 80 insertions(+), 392 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index d4c77e1..13f532d 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -29,6 +29,11 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen ui->formLayout->setVerticalSpacing(10); ui->horizontalSlider->setValue(mouse_sensivity / 100); Preferences::load_keys(); + QList lst = ui->KeyMaps->findChildren(); + qDebug() << lst.size(); + for (QList::iterator ptr = lst.begin(); ptr != lst.end();++ptr) { + qDebug() << (*ptr)->objectName(); + } } /** @@ -51,35 +56,35 @@ void Preferences::change_mouse_sensitivity(int value) void Preferences::change_key_inputs() { //change and save key maps - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = this->X; - save_setting(keymaps[setting_keys::keys::X], this->X); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = this->temp[0]; + save_setting(keymaps[setting_keys::keys::X], this->temp[0]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = this->Y; - save_setting(keymaps[setting_keys::keys::Y], this->Y); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = this->temp[1]; + save_setting(keymaps[setting_keys::keys::Y], this->temp[1]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = this->A; - save_setting(keymaps[setting_keys::keys::A], this->A); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = this->temp[2]; + save_setting(keymaps[setting_keys::keys::A], this->temp[2]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = this->B; - save_setting(keymaps[setting_keys::keys::B], this->B); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = this->temp[3]; + save_setting(keymaps[setting_keys::keys::B], this->temp[3]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = this->LT; - save_setting(keymaps[setting_keys::keys::LT], this->LT); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = this->temp[4]; + save_setting(keymaps[setting_keys::keys::LT], this->temp[4]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = this->RT; - save_setting(keymaps[setting_keys::keys::RT], this->RT); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = this->temp[5]; + save_setting(keymaps[setting_keys::keys::RT], this->temp[5]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = this->DDOWN; - save_setting(keymaps[setting_keys::keys::DPADDOWN], this->DDOWN); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = this->temp[6]; + save_setting(keymaps[setting_keys::keys::DPADDOWN], this->temp[6]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = this->DUP; - save_setting(keymaps[setting_keys::keys::DPADUP], this->DUP); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = this->temp[7]; + save_setting(keymaps[setting_keys::keys::DPADUP], this->temp[7]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = this->DRIGHT; - save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->DRIGHT); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = this->temp[8]; + save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->temp[8]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = this->DLEFT; - save_setting(keymaps[setting_keys::keys::DPADLEFT], this->DLEFT); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = this->temp[9]; + save_setting(keymaps[setting_keys::keys::DPADLEFT], this->temp[9]); } /** @@ -112,43 +117,43 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) void Preferences::load_keys() { char buffer[256]; - this->X = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]; + this->temp[0] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_X], buffer, 256); this->ui->xmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->Y = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]; + this->temp[1] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Y], buffer, 256); this->ui->ymap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->A = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]; + this->temp[2] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_A], buffer, 256); this->ui->amap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->B = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B]; + this->temp[3] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_B], buffer, 256); this->ui->bmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->RT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]; + this->temp[4] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_RightThumbstick], buffer, 256); this->ui->Rtmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->LT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]; + this->temp[5] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_LeftThumbstick], buffer, 256); this->ui->Ltmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->DDOWN = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]; + this->temp[6] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadDown], buffer, 256); this->ui->ddownmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->DUP = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]; + this->temp[7] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadUp], buffer, 256); this->ui->dupmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->DRIGHT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]; + this->temp[8] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadRight], buffer, 256); this->ui->drightmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->DLEFT = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]; + this->temp[9] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft], buffer, 256); this->ui->dleftmap->setText(QString(buffer)); } @@ -167,344 +172,42 @@ void Preferences::load_keys() */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { - if(sender == ui->xmap) { - if(event->type() == QEvent::KeyRelease && ui->xmap->text() == "") { - QKeyEvent* key_press = (QKeyEvent*)event; - this->X = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->xmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonPress && ui->xmap->text() == "") { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->X = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->X = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->X = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->xmap->setText(QString(buffer)); - } - } - else if(sender == ui->ymap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = (QKeyEvent*)event; - this->Y = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->ymap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->Y = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->Y = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->Y = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->ymap->setText(QString(buffer)); - } - } - else if(sender == ui->amap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->A = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->amap->setText(buffer); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->A = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->A = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->A = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->amap->setText(QString(buffer)); - } - } - else if(sender == ui->bmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->B = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->bmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->B = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->B = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->B = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->bmap->setText(QString(buffer)); - } - } - else if(sender == ui->Ltmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->LT = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->Ltmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->LT = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->LT = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->LT = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->Ltmap->setText(QString(buffer)); - } - } - else if(sender == ui->Rtmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->RT = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->Rtmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->RT = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->RT = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->RT = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->Rtmap->setText(QString(buffer)); - } - } - else if(sender == ui->dupmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->DUP = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->dupmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->DUP = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->DUP = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->DUP = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; + QList lst = ui->KeyMaps->findChildren(); + for(int i=0;i(sender); + if(event->type() == QEvent::KeyRelease && map->text() == "") { + QKeyEvent* key_press = (QKeyEvent*)event; + this->temp[i] = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + map->setText(QString(buffer)); } - if(valid) - ui->dupmap->setText(QString(buffer)); - } - } - else if(sender == ui->ddownmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->DDOWN = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->ddownmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->DDOWN = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->DDOWN = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->DDOWN = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; + else if(event->type() == QEvent::MouseButtonPress && map->text() == "") { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = true; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + this->temp[i] = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + break; + case Qt::MouseButton::RightButton: + this->temp[i] = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + break; + case Qt::MouseButton::MiddleButton: + this->temp[i] = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + break; + default: + qDebug() << "Some Error Occured No Legal Mouse Button found"; + valid = false; + } + if(valid) + map->setText(QString(buffer)); } - if(valid) - ui->ddownmap->setText(QString(buffer)); - } - } - else if(sender == ui->drightmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->DRIGHT = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->drightmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->DRIGHT = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->DRIGHT = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->DRIGHT = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->drightmap->setText(QString(buffer)); - } - } - else if(sender == ui->dleftmap) { - if(event->type() == QEvent::KeyRelease) { - QKeyEvent* key_press = static_cast(event); - this->DLEFT = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - ui->dleftmap->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonRelease) { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->DLEFT = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->DLEFT = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->DLEFT = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - ui->dleftmap->setText(QString(buffer)); } } return QWidget::eventFilter(sender,event); @@ -528,16 +231,10 @@ void Preferences::keyPressEvent(QKeyEvent *e) * install the above event filter on all the button maps to capture the key presses when they have the focus. */ void Preferences::install_event_filter() { - ui->xmap->installEventFilter(this); - ui->ymap->installEventFilter(this); - ui->amap->installEventFilter(this); - ui->bmap->installEventFilter(this); - ui->Ltmap->installEventFilter(this); - ui->Rtmap->installEventFilter(this); - ui->ddownmap->installEventFilter(this); - ui->dupmap->installEventFilter(this); - ui->drightmap->installEventFilter(this); - ui->dleftmap->installEventFilter(this); + QList lst = ui->KeyMaps->findChildren(); + for(QList::iterator ptr = lst.begin();ptr != lst.end(); ++ptr) { + (*ptr)->installEventFilter(this); + } } Preferences::~Preferences() diff --git a/src/preferences.h b/src/preferences.h index 705acf4..b7f75ff 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -28,16 +28,7 @@ class Preferences : public QDialog void change_key_inputs(); void get_scan_code(WORD vk, char* a, int size=256); void install_event_filter(); - UINT X; - UINT Y; - UINT A; - UINT B; - UINT LT; - UINT RT; - UINT DUP; - UINT DDOWN; - UINT DRIGHT; - UINT DLEFT; + UINT temp[10]; }; #endif // PREFERENCES_H diff --git a/src/preferences.ui b/src/preferences.ui index 407542a..a5b7621 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -193,14 +193,14 @@ - + - :/icons/icons8-xbox-rt-30.png + :/icons/icons8-xbox-lt-30.png - + 0 @@ -219,14 +219,14 @@ - + - :/icons/icons8-xbox-lt-30.png + :/icons/icons8-xbox-rt-30.png - + 0 From cfb1cbdc22d2fcb46557417981d7974fc071840c Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:17:40 +0530 Subject: [PATCH 23/31] changing the datatype of buttons --- src/networking/executor.cpp | 16 ++++++++++++++-- src/settings_key_variables.h | 7 ++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index b0d1f2d..bed706b 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -35,11 +35,23 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) { if (reading.buttons_down & button) { - keyDown(key); + if (key.is_mouse_key) { // checking if the input key is a mouse key. + if(key.vk == VK_LBUTTON) { // if it's a left mouse click execute a left click + leftClick(); + } + else if (key.vk == VK_RIGHT) { // if it's a right mouse click execute a right mouse + rightClick(); + } + + else { // else execute a middle mouse click. + middleClick(); + } + } + else keyDown(key.vk); } else if (reading.buttons_up & button) { - keyUp(key); + keyUp(key.vk); } } diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index 33060ff..c4a6895 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -6,9 +6,14 @@ #include #include "../VGP_Data_Exchange/C/GameButtons.h" +struct TRIAL{ + WORD vk; + int is_mouse_key; +}; + extern int mouse_sensivity; extern int port; -extern std::map GAMEPAD_BUTTONS; +extern std::map GAMEPAD_BUTTONS; enum Thumbstick { From cc5c86de0caf297cb6ff4e3059f96ba265160952 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Thu, 16 Nov 2023 14:38:22 +0530 Subject: [PATCH 24/31] Solving sub module changes --- VGP_Data_Exchange | 2 +- doxygen-awesome-css | 2 +- third-party-libs/QR-Code-generator | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VGP_Data_Exchange b/VGP_Data_Exchange index 463ebd3..7bcb6d4 160000 --- a/VGP_Data_Exchange +++ b/VGP_Data_Exchange @@ -1 +1 @@ -Subproject commit 463ebd330326616af44a89f9bdf41edc238d8b92 +Subproject commit 7bcb6d401a1228b2a2fa2258282f50501d8946a2 diff --git a/doxygen-awesome-css b/doxygen-awesome-css index 00a52f6..40302ce 160000 --- a/doxygen-awesome-css +++ b/doxygen-awesome-css @@ -1 +1 @@ -Subproject commit 00a52f6c74065ffbd836cbd791ddfe8edf2836b8 +Subproject commit 40302ce20f322d6243d758bb7a428818cddedd74 diff --git a/third-party-libs/QR-Code-generator b/third-party-libs/QR-Code-generator index 22fac31..49a66a2 160000 --- a/third-party-libs/QR-Code-generator +++ b/third-party-libs/QR-Code-generator @@ -1 +1 @@ -Subproject commit 22fac31bdf81da68730c177c0e931c93234d2a30 +Subproject commit 49a66a2b8bb8f8852fd2e1deb00b8672f5760139 From 688a401936522136f6d16c6d67b3ea753bdad321 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 10 Dec 2023 10:46:32 +0530 Subject: [PATCH 25/31] Revamped Preferences 1. Changed the format of saving and loading button maps. 2. Fixed the lines where memory leakage. 3. Made sure server can differentiate between mouse mapping and keyboard mapping. 4. Added some extra checks to make sure users can't put invalid inputs or perform overloading while setting the button maps. --- src/networking/executor.cpp | 2 +- src/preferences.cpp | 193 ++++++++++++++++++--------------- src/preferences.h | 3 +- src/settings.cpp | 40 +++++-- src/settings.h | 10 +- src/settings_key_variables.cpp | 31 +++--- src/settings_key_variables.h | 7 +- 7 files changed, 163 insertions(+), 123 deletions(-) diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index bed706b..a5e37e3 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -39,7 +39,7 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) if(key.vk == VK_LBUTTON) { // if it's a left mouse click execute a left click leftClick(); } - else if (key.vk == VK_RIGHT) { // if it's a right mouse click execute a right mouse + else if (key.vk == VK_RBUTTON) { // if it's a right mouse click execute a right mouse rightClick(); } diff --git a/src/preferences.cpp b/src/preferences.cpp index 13f532d..8ea26f0 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -9,8 +9,9 @@ #include #include #include +#include +#include #include "winuser.h" -#include "windows.h" Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferences) @@ -18,7 +19,7 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen ui->setupUi(this); install_event_filter(); ui->horizontalSlider->adjustSize(); - ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, [=] { // running the functions to change and save the new settings if the user presses ok + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=] { // running the functions to change and save the new settings if the user presses ok this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); qDebug() << mouse_sensivity; save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); //saving the new mouse sensivity @@ -29,11 +30,6 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen ui->formLayout->setVerticalSpacing(10); ui->horizontalSlider->setValue(mouse_sensivity / 100); Preferences::load_keys(); - QList lst = ui->KeyMaps->findChildren(); - qDebug() << lst.size(); - for (QList::iterator ptr = lst.begin(); ptr != lst.end();++ptr) { - qDebug() << (*ptr)->objectName(); - } } /** @@ -56,35 +52,45 @@ void Preferences::change_mouse_sensitivity(int value) void Preferences::change_key_inputs() { //change and save key maps - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = this->temp[0]; - save_setting(keymaps[setting_keys::keys::X], this->temp[0]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk = this->temp[ui->xmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].is_mouse_key = is_mouse_button(this->temp[ui->xmap->objectName()]); + save_setting(keymaps[setting_keys::keys::X], this->temp[ui->xmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = this->temp[1]; - save_setting(keymaps[setting_keys::keys::Y], this->temp[1]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].vk = this->temp[ui->ymap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].is_mouse_key = is_mouse_button(this->temp[ui->ymap->objectName()]); + save_setting(keymaps[setting_keys::keys::Y], this->temp[ui->ymap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = this->temp[2]; - save_setting(keymaps[setting_keys::keys::A], this->temp[2]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].vk = this->temp[ui->amap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].is_mouse_key = is_mouse_button(this->temp[ui->amap->objectName()]); + save_setting(keymaps[setting_keys::keys::A], this->temp[ui->amap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = this->temp[3]; - save_setting(keymaps[setting_keys::keys::B], this->temp[3]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].vk = this->temp[ui->bmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].is_mouse_key = is_mouse_button(this->temp[ui->bmap->objectName()]); + save_setting(keymaps[setting_keys::keys::B], this->temp[ui->bmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = this->temp[4]; - save_setting(keymaps[setting_keys::keys::LT], this->temp[4]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].vk = this->temp[ui->Ltmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].is_mouse_key = is_mouse_button(this->temp[ui->Ltmap->objectName()]); + save_setting(keymaps[setting_keys::keys::LSHDR], this->temp[ui->Ltmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = this->temp[5]; - save_setting(keymaps[setting_keys::keys::RT], this->temp[5]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].vk = this->temp[ui->Rtmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].is_mouse_key = is_mouse_button(this->temp[ui->Rtmap->objectName()]); + save_setting(keymaps[setting_keys::keys::RSHDR], this->temp[ui->Rtmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = this->temp[6]; - save_setting(keymaps[setting_keys::keys::DPADDOWN], this->temp[6]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].vk = this->temp[ui->ddownmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].is_mouse_key = is_mouse_button(this->temp[ui->ddownmap->objectName()]); + save_setting(keymaps[setting_keys::keys::DPADDOWN], this->temp[ui->ddownmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = this->temp[7]; - save_setting(keymaps[setting_keys::keys::DPADUP], this->temp[7]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].vk = this->temp[ui->dupmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].is_mouse_key = is_mouse_button(this->temp[ui->dupmap->objectName()]); + save_setting(keymaps[setting_keys::keys::DPADUP], this->temp[ui->dupmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = this->temp[8]; - save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->temp[8]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].vk = this->temp[ui->drightmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].is_mouse_key = is_mouse_button(this->temp[ui->drightmap->objectName()]); + save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->temp[ui->drightmap->objectName()]); /*------------------------------------------------------------*/ - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = this->temp[9]; - save_setting(keymaps[setting_keys::keys::DPADLEFT], this->temp[9]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].vk = this->temp[ui->dleftmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].is_mouse_key = is_mouse_button(this->temp[ui->dleftmap->objectName()]); + save_setting(keymaps[setting_keys::keys::DPADLEFT], this->temp[ui->dleftmap->objectName()]); } /** @@ -101,11 +107,13 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) { char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); if(sc >= '0' && sc <= 'Z') { - strncpy(a, "", size); - strncpy(a, &sc, 1); + //strncpy(a, "", size); + strncpy_s(a, size, "", sizeof("")); + //strncpy(a, &sc, 1); + strncpy_s(a, size, &sc, sizeof(sc)); } else { - strncpy(a, vk_maps[vk], size); + strncpy_s(a, size, vk_maps[vk], sizeof(vk_maps[vk])); } } @@ -117,44 +125,44 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) void Preferences::load_keys() { char buffer[256]; - this->temp[0] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_X], buffer, 256); + this->temp[ui->xmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk, buffer, 256); this->ui->xmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[1] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Y], buffer, 256); + this->temp[ui->ymap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Y].vk, buffer, 256); this->ui->ymap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[2] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_A], buffer, 256); + this->temp[ui->amap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_A].vk, buffer, 256); this->ui->amap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[3] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_B], buffer, 256); + this->temp[ui->bmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_B].vk, buffer, 256); this->ui->bmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[4] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_RightThumbstick], buffer, 256); + this->temp[ui->Rtmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk, buffer, 256); this->ui->Rtmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[5] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_LeftThumbstick], buffer, 256); + this->temp[ui->Ltmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk, buffer, 256); this->ui->Ltmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[6] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadDown], buffer, 256); + this->temp[ui->ddownmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk, buffer, 256); this->ui->ddownmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[7] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadUp], buffer, 256); + this->temp[ui->dupmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk, buffer, 256); this->ui->dupmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[8] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadRight], buffer, 256); + this->temp[ui->drightmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk, buffer, 256); this->ui->drightmap->setText(QString(buffer)); /*------------------------------------------------------------*/ - this->temp[9] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]; - get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft], buffer, 256); + this->temp[ui->dleftmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk, buffer, 256); this->ui->dleftmap->setText(QString(buffer)); } @@ -172,45 +180,50 @@ void Preferences::load_keys() */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { - QList lst = ui->KeyMaps->findChildren(); - for(int i=0;i(sender); - if(event->type() == QEvent::KeyRelease && map->text() == "") { - QKeyEvent* key_press = (QKeyEvent*)event; - this->temp[i] = key_press->nativeVirtualKey(); - char buffer[256]; - get_scan_code(key_press->nativeVirtualKey(), buffer, 256); - map->setText(QString(buffer)); - } - else if(event->type() == QEvent::MouseButtonPress && map->text() == "") { - QMouseEvent* mouse_press = static_cast(event); - char buffer[256]; - bool valid = true; - UINT button = mouse_press->button(); - switch(button) { - case Qt::MouseButton::LeftButton: - this->temp[i] = VK_LBUTTON; - get_scan_code(VK_LBUTTON, buffer, 256); - break; - case Qt::MouseButton::RightButton: - this->temp[i] = VK_RBUTTON; - get_scan_code(VK_RBUTTON, buffer, 256); - break; - case Qt::MouseButton::MiddleButton: - this->temp[i] = VK_MBUTTON; - get_scan_code(VK_MBUTTON, buffer, 256); - break; - default: - qDebug() << "Some Error Occured No Legal Mouse Button found"; - valid = false; - } - if(valid) - map->setText(QString(buffer)); - } - } - } - return QWidget::eventFilter(sender,event); + QLineEdit* ptr = qobject_cast(sender); + if (ptr != nullptr) { + if (event->type() == QEvent::KeyPress && ptr->text() == "") { + QKeyEvent* key_press = (QKeyEvent*)event; + temp[ptr->objectName()] = key_press->nativeVirtualKey(); + char buffer[256]; + get_scan_code(key_press->nativeVirtualKey(), buffer, 256); + ptr->setText(QString(buffer)); + return true; + } + else if (event->type() == QEvent::MouseButtonPress && ptr->text() == "") { + QMouseEvent* mouse_press = static_cast(event); + char buffer[256]; + bool valid = false; + UINT button = mouse_press->button(); + switch(button) { + case Qt::MouseButton::LeftButton: + temp[ptr->objectName()] = VK_LBUTTON; + get_scan_code(VK_LBUTTON, buffer, 256); + valid = true; + break; + case Qt::MouseButton::RightButton: + temp[ptr->objectName()] = VK_RBUTTON; + get_scan_code(VK_RBUTTON, buffer, 256); + valid = true; + break; + case Qt::MouseButton::MiddleButton: + temp[ptr->objectName()] = VK_MBUTTON; + get_scan_code(VK_MBUTTON, buffer, 256); + valid = true; + break; + default: + qDebug() << "[!] Error Occured No Legal Mouse Button Found"; + } + if(valid) + ptr->setText(QString(buffer)); + return true; + } + else { + if ((event->type() == QEvent::KeyPress || event->type() == QEvent::MouseButtonPress) && ptr->hasFocus()) + return true; + } + } + return QWidget::eventFilter(sender, event); } /** @@ -233,7 +246,7 @@ void Preferences::keyPressEvent(QKeyEvent *e) void Preferences::install_event_filter() { QList lst = ui->KeyMaps->findChildren(); for(QList::iterator ptr = lst.begin();ptr != lst.end(); ++ptr) { - (*ptr)->installEventFilter(this); + (*ptr)->installEventFilter(this); } } diff --git a/src/preferences.h b/src/preferences.h index b7f75ff..7e2b79b 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -2,6 +2,7 @@ #define PREFERENCES_H #include +#include #include namespace Ui @@ -28,7 +29,7 @@ class Preferences : public QDialog void change_key_inputs(); void get_scan_code(WORD vk, char* a, int size=256); void install_event_filter(); - UINT temp[10]; + std::map temp; }; #endif // PREFERENCES_H diff --git a/src/settings.cpp b/src/settings.cpp index ef69a0c..24d9674 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,6 +1,8 @@ #include "settings.h" -#include "settings_key_variables.h" #include +#include "settings_key_variables.h" + +using namespace setting_keys; QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini QSettings *settings; @@ -74,16 +76,16 @@ void load_port_number() // set the port number as user_defined */ void load_key_maps() // set the key mappings to the stored values { - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A] = (WORD)settings->value(keymaps[setting_keys::keys::A], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B] = (WORD)settings->value(keymaps[setting_keys::keys::B], GAMEPAD_BUTTONS[GamepadButtons_B]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X] = (WORD)settings->value(keymaps[setting_keys::keys::X], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y] = (WORD)settings->value(keymaps[setting_keys::keys::Y], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::LT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftThumbstick]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick] = (WORD)settings->value(keymaps[setting_keys::keys::RT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightThumbstick]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown] = (WORD)settings->value(keymaps[setting_keys::keys::DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown]).toULongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp] = (WORD)settings->value(keymaps[setting_keys::keys::DPADUP], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp]).toLongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight] = (WORD)settings->value(keymaps[setting_keys::keys::DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight]).toLongLong(); - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft] = (WORD)settings->value(keymaps[setting_keys::keys::DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft]).toLongLong(); + GAMEPAD_BUTTONS[GamepadButtons_A] = TRIAL{(WORD)settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong(), is_mouse_button(settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_B] = TRIAL{(WORD)settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong(), is_mouse_button(settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_X] = TRIAL{(WORD)settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong(), is_mouse_button(settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_Y] = TRIAL{(WORD)settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong(), is_mouse_button(settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder] = TRIAL{(WORD)settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong(), is_mouse_button(settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_RightShoulder] = TRIAL{(WORD)settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong(), is_mouse_button(settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadDown] = TRIAL{(WORD)settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong(), is_mouse_button(settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadUp] = TRIAL{(WORD)settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadRight] = TRIAL{(WORD)settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = TRIAL{(WORD)settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong())}; } /** @@ -97,3 +99,19 @@ void load_all_settings() { } +/** + * @brief is_mouse_button + * function to find out if the user mapped a keyboard key or mouse button + * @param vk + * virtual key code of the key or mouse button pressed + * @return + * returns 1 if its a mouse button else 0 + */ +uint is_mouse_button(UINT vk) +{ + for (uint i=0;i<3;++i) { + if (MOUSE_BUTTONS[i] == vk) + return 1; + } + return 0; +} diff --git a/src/settings.h b/src/settings.h index 3852681..f9afbe4 100644 --- a/src/settings.h +++ b/src/settings.h @@ -2,6 +2,7 @@ #define SETTINGS_H #include #include +#include extern QString SETTINGS_FILE; @@ -21,8 +22,8 @@ enum keys B, X, Y, - RT, - LT, + RSHDR, + LSHDR, DPADDOWN, DPADUP, DPADRIGHT, @@ -42,8 +43,8 @@ inline QMap keymaps = {{setting_keys::keys::A, "key {setting_keys::keys::B, "keymaps/B"}, {setting_keys::keys::X, "keymaps/X"}, {setting_keys::keys::Y, "keymaps/Y"}, - {setting_keys::keys::RT, "keymaps/RT"}, - {setting_keys::keys::LT, "keymaps/LT"}, + {setting_keys::keys::RSHDR, "keymaps/RT"}, + {setting_keys::keys::LSHDR, "keymaps/LT"}, {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, @@ -58,5 +59,6 @@ void load_settings_file(QObject *parent); void load_port_number(); void load_key_maps(); void load_all_settings(); +uint is_mouse_button(UINT vk); #endif // SETTINGS_H diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index fe55c8f..59f1b17 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -7,20 +7,21 @@ int port = 7878; // the port on which the server runs on. * @brief GAMEPAD_BUTTONS * a map for the gamepad button and the corresponding input. */ -std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, VK_MENU}, - {GamepadButtons::GamepadButtons_View, VK_TAB}, - {GamepadButtons::GamepadButtons_A, VK_RETURN}, - {GamepadButtons::GamepadButtons_B, 'B'}, - {GamepadButtons::GamepadButtons_X, VK_SHIFT}, - {GamepadButtons::GamepadButtons_Y, VK_CONTROL}, - {GamepadButtons::GamepadButtons_DPadUp, VK_UP}, - {GamepadButtons::GamepadButtons_DPadDown, VK_DOWN}, - {GamepadButtons::GamepadButtons_DPadLeft, VK_LEFT}, - {GamepadButtons::GamepadButtons_DPadRight, VK_RIGHT}, -// {GamepadButtons::GamepadButtons_LeftShoulder, 'E'}, -// {GamepadButtons::GamepadButtons_RightShoulder, VK_SPACE}, - {GamepadButtons::GamepadButtons_LeftThumbstick, VK_LBUTTON}, - {GamepadButtons::GamepadButtons_RightThumbstick, VK_NEXT}}; +std::map GAMEPAD_BUTTONS = { + {GamepadButtons::GamepadButtons_Menu, TRIAL{VK_MENU, 0}}, + {GamepadButtons::GamepadButtons_View, TRIAL{VK_TAB, 0}}, + {GamepadButtons::GamepadButtons_A, TRIAL{VK_RETURN, 0}}, + {GamepadButtons::GamepadButtons_B, TRIAL{'B', 0}}, + {GamepadButtons::GamepadButtons_X, TRIAL{VK_SHIFT, 0}}, + {GamepadButtons::GamepadButtons_Y, TRIAL{VK_CONTROL, 0}}, + {GamepadButtons::GamepadButtons_DPadUp, TRIAL{VK_UP, 0}}, + {GamepadButtons::GamepadButtons_DPadDown, TRIAL{VK_DOWN, 0}}, + {GamepadButtons::GamepadButtons_DPadLeft, TRIAL{VK_LEFT, 0}}, + {GamepadButtons::GamepadButtons_DPadRight, TRIAL{VK_RIGHT, 0}}, + {GamepadButtons::GamepadButtons_LeftShoulder, TRIAL{VK_LBUTTON, 1}}, + {GamepadButtons::GamepadButtons_RightShoulder, TRIAL{VK_NEXT, 0}}}; + // {GamepadButtons::GamepadButtons_LeftThumbstick, TRIAL{VK_LBUTTON, 1}}, + // {GamepadButtons::GamepadButtons_RightThumbstick, TRIAL{VK_NEXT, 0}}}; /** * @brief THUMBSTICK_KEYS @@ -63,3 +64,5 @@ std::map vk_maps = { {VK_OEM_MINUS, "-"}, {VK_OEM_PLUS, "+"} }; + +const QList MOUSE_BUTTONS = {VK_LBUTTON, VK_RBUTTON, VK_MBUTTON}; diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index c4a6895..bdd94b5 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -2,13 +2,14 @@ #ifndef SETTINGS_KEY_VARIABLES_H #define SETTINGS_KEY_VARIABLES_H #include +#include #include #include "../VGP_Data_Exchange/C/GameButtons.h" struct TRIAL{ - WORD vk; - int is_mouse_key; + WORD vk; + uint is_mouse_key = 0; }; extern int mouse_sensivity; @@ -30,4 +31,6 @@ enum Thumbstick extern std::map THUMBSTICK_KEYS; extern std::map vk_maps; +extern const QList MOUSE_BUTTONS; + #endif // SETTINGS_KEY_VARIABLES_H From 52ce45127c3fef51535a07cd66995560eee982cf Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 10 Dec 2023 10:58:23 +0530 Subject: [PATCH 26/31] Sound Cloud Suggestions Fixing some of the code smells Sound Cloud suggested that are fixable. --- src/preferences.cpp | 11 ++++------- src/settings.cpp | 2 +- src/settings.h | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index 8ea26f0..b111612 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -107,9 +107,7 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) { char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); if(sc >= '0' && sc <= 'Z') { - //strncpy(a, "", size); strncpy_s(a, size, "", sizeof("")); - //strncpy(a, &sc, 1); strncpy_s(a, size, &sc, sizeof(sc)); } else { @@ -180,10 +178,9 @@ void Preferences::load_keys() */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { - QLineEdit* ptr = qobject_cast(sender); - if (ptr != nullptr) { + if (QLineEdit* ptr = qobject_cast(sender); ptr) { if (event->type() == QEvent::KeyPress && ptr->text() == "") { - QKeyEvent* key_press = (QKeyEvent*)event; + const QKeyEvent* key_press = (QKeyEvent*)event; temp[ptr->objectName()] = key_press->nativeVirtualKey(); char buffer[256]; get_scan_code(key_press->nativeVirtualKey(), buffer, 256); @@ -191,7 +188,7 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) return true; } else if (event->type() == QEvent::MouseButtonPress && ptr->text() == "") { - QMouseEvent* mouse_press = static_cast(event); + const QMouseEvent* mouse_press = static_cast(event); char buffer[256]; bool valid = false; UINT button = mouse_press->button(); @@ -245,7 +242,7 @@ void Preferences::keyPressEvent(QKeyEvent *e) */ void Preferences::install_event_filter() { QList lst = ui->KeyMaps->findChildren(); - for(QList::iterator ptr = lst.begin();ptr != lst.end(); ++ptr) { + for(auto ptr = lst.begin();ptr != lst.end(); ++ptr) { (*ptr)->installEventFilter(this); } } diff --git a/src/settings.cpp b/src/settings.cpp index 24d9674..3640977 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -4,7 +4,7 @@ using namespace setting_keys; -QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini +const QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini QSettings *settings; QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; diff --git a/src/settings.h b/src/settings.h index f9afbe4..70c1d06 100644 --- a/src/settings.h +++ b/src/settings.h @@ -4,7 +4,7 @@ #include #include -extern QString SETTINGS_FILE; +extern const QString SETTINGS_FILE; namespace setting_keys // a name space to maintain the key names. { From 24e383637511156f80953275ad0ba754e1059b2e Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Sun, 10 Dec 2023 17:57:01 +0530 Subject: [PATCH 27/31] Documentation changes Changing the Documentation according to your suggestions. https://github.com/kitswas/VirtualGamePad-PC/pull/5#issuecomment-1702666810 --- src/preferences.cpp | 39 +++++++++++++++++----------------- src/settings.cpp | 32 +++++++++++++--------------- src/settings_key_variables.cpp | 10 ++++++--- src/settings_key_variables.h | 4 ++++ 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/preferences.cpp b/src/preferences.cpp index b111612..ada5ca2 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -34,9 +34,9 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen /** * @brief Preferences::change_mouse_sensitivity - * changes the mouse sensivity or the cursor speed + * Changes the mouse sensivity or the cursor speed * @param value - * the amount of mouse sensivity you want to set. + * The amount of mouse sensivity you want to set. */ void Preferences::change_mouse_sensitivity(int value) { @@ -45,8 +45,8 @@ void Preferences::change_mouse_sensitivity(int value) /** * @brief Preferences::change_key_inputs - * this changes the keyboard maps and saves those changes in the config file. - * this function is executed if the user presses ok button. + * This changes the keyboard maps and saves those changes in the config file. + * This function is executed if the user presses ok button. */ void Preferences::change_key_inputs() @@ -95,13 +95,13 @@ void Preferences::change_key_inputs() /** * @brief Preferences::get_scan_code - * gets the name of the of corrosponding key or virutal key code. + * Copies the name of the of corrosponding key or virutal key code to the provided buffer. * @param vk - * the virtual key code of the key you want to get. + * The virtual key code of the key you want to get. * @param a - * the buffer to store the name of the key. + * The buffer to store the name of the key. * @param size - * size of the buffer in which the name is stored to ensure memory safety + * Size of the buffer(in char) in which the name is stored to ensure memory safety */ void Preferences::get_scan_code(WORD vk, char* a, int size) { @@ -117,8 +117,8 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) /** * @brief Preferences::load_keys - * displays the key to which each button is mapped to. - * saves the initial key maps in variables that can be changed later if user wants to. + * Displays the key to which each button is mapped to. + * Saves the initial key maps in variables that can be changed later if user wants to. */ void Preferences::load_keys() { @@ -166,15 +166,14 @@ void Preferences::load_keys() /** * @brief Preferences::eventFilter - * the event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change the button-key maps. - * checks which object is sending the event and type of event. - * if event is a keyboard or mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the change in a temporary variable. + * The event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change the button-key maps. + * Checks which object is sending the event and type of event. + * If event is a keyboard or mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the change in a temporary variable. * @param sender - * to get the address of the object that is triggering the event. + * To get the address of the object that is triggering the event. * @param event - * to capture the event that was triggered. - * @return [bool] - * true if event is handled else false. + * To capture the event that was triggered. + * @return [bool] True if event is handled else False. */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { @@ -225,9 +224,9 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) /** * @brief Preferences::keyPressEvent - * make the Qdialog box ignores the enter key and escape key presses when the focus is on button map + * Make the Qdialog box ignores the enter key and escape key presses when the focus is on button map * @param e - * capture the key_press event + * Capture the key_press event */ void Preferences::keyPressEvent(QKeyEvent *e) { @@ -238,7 +237,7 @@ void Preferences::keyPressEvent(QKeyEvent *e) /** * @brief Preferences::install_event_filter - * install the above event filter on all the button maps to capture the key presses when they have the focus. + * Install the above event filter on all the button maps to capture the key presses when they have the focus. */ void Preferences::install_event_filter() { QList lst = ui->KeyMaps->findChildren(); diff --git a/src/settings.cpp b/src/settings.cpp index 3640977..410cbd3 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -13,11 +13,11 @@ void (*load_functions[3])(void) = {load_mouse_setting, load_port_number, load_ke /** * @brief save_setting - * save a setting to the settings file + * Save a setting to the settings file * @param key - * the name of the setting in string format if you want to group settings seperate the head group using + * The name of the setting in string format if you want to group settings seperate the head group using * @param value - * the value of the settings can be of any data type string, int, char, float, e.t.c. + * The value of the settings can be of any data type string, int, char, float, e.t.c. */ void save_setting(QString key, QVariant value) { @@ -29,11 +29,10 @@ void save_setting(QString key, QVariant value) /** * @brief load_setting - * get the value of a setting. + * Get the value of a setting. * @param key - * the fullname including the groups of the setting in string format - * @return - * the setting as QVariant can be converted into almost all data types. + * The fullname including the groups of the setting in string format + * @return The setting as QVariant can be converted into almost all data types. */ QVariant load_setting(QString key) { @@ -43,7 +42,7 @@ QVariant load_setting(QString key) /** * @brief load_mouse_setting - * loads and sets the mouse sensivity. + * Loads and sets the mouse sensivity. */ void load_mouse_setting() { @@ -52,9 +51,9 @@ void load_mouse_setting() /** * @brief load_settings_file - * loads the settings file for the current application. + * Loads the settings file for the current application. * @param parent - * the parent object either a widget or Qt Application e.t.c + * The parent object either a widget or Qt Application e.t.c */ void load_settings_file(QObject *parent = nullptr) { @@ -63,7 +62,7 @@ void load_settings_file(QObject *parent = nullptr) /** * @brief load_port_number - * load and set the port number + * Load and set the port number */ void load_port_number() // set the port number as user_defined { @@ -72,7 +71,7 @@ void load_port_number() // set the port number as user_defined /** * @brief load_key_maps - * load the key maps from the settings file. + * Load the key maps from the settings file. */ void load_key_maps() // set the key mappings to the stored values { @@ -90,7 +89,7 @@ void load_key_maps() // set the key mappings to the stored values /** * @brief load_all_settings - * run the functions using the function array to load all the necessary settings. + * Run the functions using the function array to load all the necessary settings. */ void load_all_settings() { for(int i=0;i<3;i++) { @@ -101,11 +100,10 @@ void load_all_settings() { /** * @brief is_mouse_button - * function to find out if the user mapped a keyboard key or mouse button + * Function to find out if the user mapped a keyboard key or mouse button * @param vk - * virtual key code of the key or mouse button pressed - * @return - * returns 1 if its a mouse button else 0 + * Virtual key code of the key or mouse button pressed + * @return 1 if its a mouse button else 0 */ uint is_mouse_button(UINT vk) { diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 59f1b17..b9e9da6 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -5,7 +5,7 @@ int port = 7878; // the port on which the server runs on. /** * @brief GAMEPAD_BUTTONS - * a map for the gamepad button and the corresponding input. + * A map for the gamepad button and the corresponding input. */ std::map GAMEPAD_BUTTONS = { {GamepadButtons::GamepadButtons_Menu, TRIAL{VK_MENU, 0}}, @@ -25,7 +25,7 @@ std::map GAMEPAD_BUTTONS = { /** * @brief THUMBSTICK_KEYS - * maps the joystick movements. + * Maps the joystick movements. */ std::map THUMBSTICK_KEYS = { {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, @@ -35,7 +35,7 @@ std::map THUMBSTICK_KEYS = { /** * @brief vk_maps - * a std::map to map the virtual key codes to corresponding key names + * A std::map to map the virtual key codes to corresponding key names */ std::map vk_maps = { {VK_LBUTTON, "LMButton"}, @@ -65,4 +65,8 @@ std::map vk_maps = { {VK_OEM_PLUS, "+"} }; +/** + * @brief MOUSE_BUTTONS + * A list containing the Mouse Buttons. + */ const QList MOUSE_BUTTONS = {VK_LBUTTON, VK_RBUTTON, VK_MBUTTON}; diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index bdd94b5..e97a921 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -7,6 +7,10 @@ #include #include "../VGP_Data_Exchange/C/GameButtons.h" +/** + * @brief The TRIAL Struct + * A structure to hold the button mappings. + */ struct TRIAL{ WORD vk; uint is_mouse_key = 0; From fdbd0200c5c69e6ccae67677572e394e3babbee3 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 15 Dec 2023 20:16:50 +0530 Subject: [PATCH 28/31] Applying Clang-Format to the code --- src/mainwindow.cpp | 4 +- src/networking/executor.cpp | 32 +++--- src/networking/executor.hpp | 3 - src/networking/server.cpp | 2 +- src/preferences.cpp | 187 ++++++++++++++++++--------------- src/preferences.h | 16 +-- src/settings.cpp | 74 +++++++++---- src/settings.h | 25 +++-- src/settings_key_variables.cpp | 69 ++++++------ src/settings_key_variables.h | 25 ++--- 10 files changed, 242 insertions(+), 195 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1baed30..70a65e2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -9,10 +9,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi { load_settings_file(this); load_mouse_setting(); - load_key_maps(); + load_key_maps(); this->p = new Preferences(this); ui->setupUi(this); - ui->settingsButton->connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); + ui->settingsButton->connect(ui->settingsButton, &QPushButton::pressed, this, [=] { this->p->show(); }); } MainWindow::~MainWindow() diff --git a/src/networking/executor.cpp b/src/networking/executor.cpp index a5e37e3..0b97b14 100644 --- a/src/networking/executor.cpp +++ b/src/networking/executor.cpp @@ -5,7 +5,6 @@ #define THRESHOLD 0.5 - vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t len) { vgp_data_exchange_gamepad_reading reading; @@ -35,23 +34,28 @@ bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading) { if (reading.buttons_down & button) { - if (key.is_mouse_key) { // checking if the input key is a mouse key. - if(key.vk == VK_LBUTTON) { // if it's a left mouse click execute a left click - leftClick(); - } - else if (key.vk == VK_RBUTTON) { // if it's a right mouse click execute a right mouse - rightClick(); - } + if (key.is_mouse_key) + { // checking if the input key is a mouse key. + if (key.vk == VK_LBUTTON) + { // if it's a left mouse click execute a left click + leftClick(); + } + else if (key.vk == VK_RBUTTON) + { // if it's a right mouse click execute a right mouse + rightClick(); + } - else { // else execute a middle mouse click. - middleClick(); - } - } - else keyDown(key.vk); + else + { // else execute a middle mouse click. + middleClick(); + } + } + else + keyDown(key.vk); } else if (reading.buttons_up & button) { - keyUp(key.vk); + keyUp(key.vk); } } diff --git a/src/networking/executor.hpp b/src/networking/executor.hpp index 0d92425..b47729e 100644 --- a/src/networking/executor.hpp +++ b/src/networking/executor.hpp @@ -3,8 +3,5 @@ #include "../../VGP_Data_Exchange/C/Colfer.h" #include "../simulation/simulate.hpp" - - - vgp_data_exchange_gamepad_reading parse_gamepad_state(const char *data, size_t len); bool inject_gamepad_state(vgp_data_exchange_gamepad_reading reading); diff --git a/src/networking/server.cpp b/src/networking/server.cpp index 40902b5..5f068b4 100644 --- a/src/networking/server.cpp +++ b/src/networking/server.cpp @@ -74,7 +74,7 @@ Server::~Server() void Server::initServer() { tcpServer->setListenBacklogSize(0); - if (!tcpServer->listen(QHostAddress::AnyIPv4, port)) + if (!tcpServer->listen(QHostAddress::AnyIPv4, port)) { QMessageBox::critical(this, tr("VGamepad Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString())); diff --git a/src/preferences.cpp b/src/preferences.cpp index ada5ca2..b4cdd97 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -1,35 +1,36 @@ #include "preferences.h" -#include "settings_key_variables.h" #include "settings.h" +#include "settings_key_variables.h" #include "ui_preferences.h" +#include "winuser.h" #include -#include -#include +#include #include #include +#include #include -#include +#include #include -#include -#include "winuser.h" - +#include Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferences) { ui->setupUi(this); - install_event_filter(); + install_event_filter(); ui->horizontalSlider->adjustSize(); - ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, this, [=] { // running the functions to change and save the new settings if the user presses ok - this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); - qDebug() << mouse_sensivity; - save_setting(setting_keys::Mouse_sensivity, mouse_sensivity / 100); //saving the new mouse sensivity - change_key_inputs(); //changing and saving key maps - }); - ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); - ui->formLayout->setHorizontalSpacing(50); - ui->formLayout->setVerticalSpacing(10); + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::accepted, this, + [=] { // running the functions to change and save the new settings if the user presses ok + this->change_mouse_sensitivity(ui->horizontalSlider->value() * 100); + qDebug() << mouse_sensivity; + save_setting(setting_keys::Mouse_sensivity, + mouse_sensivity / 100); // saving the new mouse sensivity + change_key_inputs(); // changing and saving key maps + }); + ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); + ui->formLayout->setHorizontalSpacing(50); + ui->formLayout->setVerticalSpacing(10); ui->horizontalSlider->setValue(mouse_sensivity / 100); - Preferences::load_keys(); + Preferences::load_keys(); } /** @@ -51,45 +52,55 @@ void Preferences::change_mouse_sensitivity(int value) void Preferences::change_key_inputs() { - //change and save key maps + // change and save key maps GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk = this->temp[ui->xmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].is_mouse_key = is_mouse_button(this->temp[ui->xmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].is_mouse_key = + is_mouse_button(this->temp[ui->xmap->objectName()]); save_setting(keymaps[setting_keys::keys::X], this->temp[ui->xmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].vk = this->temp[ui->ymap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].is_mouse_key = is_mouse_button(this->temp[ui->ymap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].is_mouse_key = + is_mouse_button(this->temp[ui->ymap->objectName()]); save_setting(keymaps[setting_keys::keys::Y], this->temp[ui->ymap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].vk = this->temp[ui->amap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].is_mouse_key = is_mouse_button(this->temp[ui->amap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].is_mouse_key = + is_mouse_button(this->temp[ui->amap->objectName()]); save_setting(keymaps[setting_keys::keys::A], this->temp[ui->amap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].vk = this->temp[ui->bmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].is_mouse_key = is_mouse_button(this->temp[ui->bmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].is_mouse_key = + is_mouse_button(this->temp[ui->bmap->objectName()]); save_setting(keymaps[setting_keys::keys::B], this->temp[ui->bmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].vk = this->temp[ui->Ltmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].is_mouse_key = is_mouse_button(this->temp[ui->Ltmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].is_mouse_key = + is_mouse_button(this->temp[ui->Ltmap->objectName()]); save_setting(keymaps[setting_keys::keys::LSHDR], this->temp[ui->Ltmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].vk = this->temp[ui->Rtmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].is_mouse_key = is_mouse_button(this->temp[ui->Rtmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].is_mouse_key = + is_mouse_button(this->temp[ui->Rtmap->objectName()]); save_setting(keymaps[setting_keys::keys::RSHDR], this->temp[ui->Rtmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].vk = this->temp[ui->ddownmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].is_mouse_key = is_mouse_button(this->temp[ui->ddownmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].is_mouse_key = + is_mouse_button(this->temp[ui->ddownmap->objectName()]); save_setting(keymaps[setting_keys::keys::DPADDOWN], this->temp[ui->ddownmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].vk = this->temp[ui->dupmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].is_mouse_key = is_mouse_button(this->temp[ui->dupmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].is_mouse_key = + is_mouse_button(this->temp[ui->dupmap->objectName()]); save_setting(keymaps[setting_keys::keys::DPADUP], this->temp[ui->dupmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].vk = this->temp[ui->drightmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].is_mouse_key = is_mouse_button(this->temp[ui->drightmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].is_mouse_key = + is_mouse_button(this->temp[ui->drightmap->objectName()]); save_setting(keymaps[setting_keys::keys::DPADRIGHT], this->temp[ui->drightmap->objectName()]); - /*------------------------------------------------------------*/ + /*------------------------------------------------------------*/ GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].vk = this->temp[ui->dleftmap->objectName()]; - GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].is_mouse_key = is_mouse_button(this->temp[ui->dleftmap->objectName()]); + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].is_mouse_key = + is_mouse_button(this->temp[ui->dleftmap->objectName()]); save_setting(keymaps[setting_keys::keys::DPADLEFT], this->temp[ui->dleftmap->objectName()]); } @@ -103,16 +114,18 @@ void Preferences::change_key_inputs() * @param size * Size of the buffer(in char) in which the name is stored to ensure memory safety */ -void Preferences::get_scan_code(WORD vk, char* a, int size) +void Preferences::get_scan_code(WORD vk, char *a, int size) { - char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); - if(sc >= '0' && sc <= 'Z') { + char sc = MapVirtualKeyA((UINT)vk, MAPVK_VK_TO_CHAR); + if (sc >= '0' && sc <= 'Z') + { strncpy_s(a, size, "", sizeof("")); strncpy_s(a, size, &sc, sizeof(sc)); - } - else { + } + else + { strncpy_s(a, size, vk_maps[vk], sizeof(vk_maps[vk])); - } + } } /** @@ -122,53 +135,54 @@ void Preferences::get_scan_code(WORD vk, char* a, int size) */ void Preferences::load_keys() { - char buffer[256]; + char buffer[256]; this->temp[ui->xmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_X].vk, buffer, 256); - this->ui->xmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->xmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->ymap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Y].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Y].vk, buffer, 256); - this->ui->ymap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->ymap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->amap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_A].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_A].vk, buffer, 256); - this->ui->amap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->amap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->bmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_B].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_B].vk, buffer, 256); - this->ui->bmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->bmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->Rtmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_RightShoulder].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk, buffer, 256); - this->ui->Rtmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->Rtmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->Ltmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_LeftShoulder].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk, buffer, 256); - this->ui->Ltmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->Ltmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->ddownmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadDown].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk, buffer, 256); - this->ui->ddownmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->ddownmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->dupmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadUp].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk, buffer, 256); - this->ui->dupmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->dupmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->drightmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadRight].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk, buffer, 256); - this->ui->drightmap->setText(QString(buffer)); - /*------------------------------------------------------------*/ + this->ui->drightmap->setText(QString(buffer)); + /*------------------------------------------------------------*/ this->temp[ui->dleftmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk, buffer, 256); - this->ui->dleftmap->setText(QString(buffer)); + this->ui->dleftmap->setText(QString(buffer)); } /** * @brief Preferences::eventFilter - * The event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change the button-key maps. - * Checks which object is sending the event and type of event. - * If event is a keyboard or mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the change in a temporary variable. + * The event filter virtual function is redefined to to filter for mouse and keyboard inputs when user tries to change + * the button-key maps. Checks which object is sending the event and type of event. If event is a keyboard or + * mousebutton press than map and the object is buttonmap than get the virtual key code of the key pressed and store the + * change in a temporary variable. * @param sender * To get the address of the object that is triggering the event. * @param event @@ -177,21 +191,25 @@ void Preferences::load_keys() */ bool Preferences::eventFilter(QObject *sender, QEvent *event) { - if (QLineEdit* ptr = qobject_cast(sender); ptr) { - if (event->type() == QEvent::KeyPress && ptr->text() == "") { - const QKeyEvent* key_press = (QKeyEvent*)event; + if (QLineEdit *ptr = qobject_cast(sender); ptr) + { + if (event->type() == QEvent::KeyPress && ptr->text() == "") + { + const QKeyEvent *key_press = (QKeyEvent *)event; temp[ptr->objectName()] = key_press->nativeVirtualKey(); char buffer[256]; get_scan_code(key_press->nativeVirtualKey(), buffer, 256); ptr->setText(QString(buffer)); return true; } - else if (event->type() == QEvent::MouseButtonPress && ptr->text() == "") { - const QMouseEvent* mouse_press = static_cast(event); + else if (event->type() == QEvent::MouseButtonPress && ptr->text() == "") + { + const QMouseEvent *mouse_press = static_cast(event); char buffer[256]; bool valid = false; UINT button = mouse_press->button(); - switch(button) { + switch (button) + { case Qt::MouseButton::LeftButton: temp[ptr->objectName()] = VK_LBUTTON; get_scan_code(VK_LBUTTON, buffer, 256); @@ -210,11 +228,12 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) default: qDebug() << "[!] Error Occured No Legal Mouse Button Found"; } - if(valid) + if (valid) ptr->setText(QString(buffer)); return true; } - else { + else + { if ((event->type() == QEvent::KeyPress || event->type() == QEvent::MouseButtonPress) && ptr->hasFocus()) return true; } @@ -230,23 +249,25 @@ bool Preferences::eventFilter(QObject *sender, QEvent *event) */ void Preferences::keyPressEvent(QKeyEvent *e) { - if(e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Escape) - return; - return QDialog::keyPressEvent(e); + if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Escape) + return; + return QDialog::keyPressEvent(e); } /** * @brief Preferences::install_event_filter * Install the above event filter on all the button maps to capture the key presses when they have the focus. */ -void Preferences::install_event_filter() { - QList lst = ui->KeyMaps->findChildren(); - for(auto ptr = lst.begin();ptr != lst.end(); ++ptr) { +void Preferences::install_event_filter() +{ + QList lst = ui->KeyMaps->findChildren(); + for (auto ptr = lst.begin(); ptr != lst.end(); ++ptr) + { (*ptr)->installEventFilter(this); - } + } } Preferences::~Preferences() { - delete ui; + delete ui; } diff --git a/src/preferences.h b/src/preferences.h index 7e2b79b..26e5549 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -15,20 +15,20 @@ class Preferences : public QDialog Q_OBJECT public: - explicit Preferences(QWidget *parent = nullptr); - void load_keys(); + explicit Preferences(QWidget *parent = nullptr); + void load_keys(); ~Preferences(); protected: - bool eventFilter(QObject* sender, QEvent* event); - void keyPressEvent(QKeyEvent *e); + bool eventFilter(QObject *sender, QEvent *event); + void keyPressEvent(QKeyEvent *e); private: Ui::Preferences *ui; - void change_mouse_sensitivity(int value); - void change_key_inputs(); - void get_scan_code(WORD vk, char* a, int size=256); - void install_event_filter(); + void change_mouse_sensitivity(int value); + void change_key_inputs(); + void get_scan_code(WORD vk, char *a, int size = 256); + void install_event_filter(); std::map temp; }; diff --git a/src/settings.cpp b/src/settings.cpp index 410cbd3..be4ad9b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,15 +1,18 @@ #include "settings.h" -#include #include "settings_key_variables.h" +#include using namespace setting_keys; -const QString SETTINGS_FILE = QDir::toNativeSeparators(QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini +const QString SETTINGS_FILE = QDir::toNativeSeparators( + QDir::homePath() + "//VirtualGamePad.ini"); // the path of the settigs file. C:\Users\\VirtualGamePad.ini QSettings *settings; QString setting_keys::Mouse_sensivity = "mouse_setting/mouse_sensivity"; -void (*load_functions[3])(void) = {load_mouse_setting, load_port_number, load_key_maps}; // an array of pointer to functions that needs to run on startup to load settings. +void (*load_functions[3])(void) = { + load_mouse_setting, load_port_number, + load_key_maps}; // an array of pointer to functions that needs to run on startup to load settings. /** * @brief save_setting @@ -23,8 +26,8 @@ void save_setting(QString key, QVariant value) { settings->setValue(key, value); settings->sync(); - qDebug() << settings->value(key).toString(); - qDebug() << settings->fileName(); + qDebug() << settings->value(key).toString(); + qDebug() << settings->fileName(); } /** @@ -46,7 +49,7 @@ QVariant load_setting(QString key) */ void load_mouse_setting() { - mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; + mouse_sensivity = settings->value(setting_keys::Mouse_sensivity).toInt() * 100; } /** @@ -66,7 +69,7 @@ void load_settings_file(QObject *parent = nullptr) */ void load_port_number() // set the port number as user_defined { - port = settings->value(server_settings[setting_keys::Port]).toInt(); + port = settings->value(server_settings[setting_keys::Port]).toInt(); } /** @@ -75,29 +78,53 @@ void load_port_number() // set the port number as user_defined */ void load_key_maps() // set the key mappings to the stored values { - GAMEPAD_BUTTONS[GamepadButtons_A] = TRIAL{(WORD)settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong(), is_mouse_button(settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_B] = TRIAL{(WORD)settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong(), is_mouse_button(settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_X] = TRIAL{(WORD)settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong(), is_mouse_button(settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_Y] = TRIAL{(WORD)settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong(), is_mouse_button(settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder] = TRIAL{(WORD)settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong(), is_mouse_button(settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_RightShoulder] = TRIAL{(WORD)settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong(), is_mouse_button(settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadDown] = TRIAL{(WORD)settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong(), is_mouse_button(settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadUp] = TRIAL{(WORD)settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadRight] = TRIAL{(WORD)settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong())}; - GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = TRIAL{(WORD)settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_A] = + TRIAL{(WORD)settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong(), + is_mouse_button(settings->value(keymaps[A], GAMEPAD_BUTTONS[GamepadButtons_A].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_B] = + TRIAL{(WORD)settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong(), + is_mouse_button(settings->value(keymaps[B], GAMEPAD_BUTTONS[GamepadButtons_B].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_X] = + TRIAL{(WORD)settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong(), + is_mouse_button(settings->value(keymaps[X], GAMEPAD_BUTTONS[GamepadButtons_X].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_Y] = + TRIAL{(WORD)settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong(), + is_mouse_button(settings->value(keymaps[Y], GAMEPAD_BUTTONS[GamepadButtons_Y].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder] = + TRIAL{(WORD)settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong(), + is_mouse_button( + settings->value(keymaps[LSHDR], GAMEPAD_BUTTONS[GamepadButtons_LeftShoulder].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_RightShoulder] = + TRIAL{(WORD)settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong(), + is_mouse_button( + settings->value(keymaps[RSHDR], GAMEPAD_BUTTONS[GamepadButtons_RightShoulder].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadDown] = TRIAL{ + (WORD)settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong(), + is_mouse_button(settings->value(keymaps[DPADDOWN], GAMEPAD_BUTTONS[GamepadButtons_DPadDown].vk).toULongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadUp] = TRIAL{ + (WORD)settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong(), + is_mouse_button(settings->value(keymaps[DPADUP], GAMEPAD_BUTTONS[GamepadButtons_DPadUp].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadRight] = + TRIAL{(WORD)settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong(), + is_mouse_button( + settings->value(keymaps[DPADRIGHT], GAMEPAD_BUTTONS[GamepadButtons_DPadRight].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = TRIAL{ + (WORD)settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong(), + is_mouse_button(settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong())}; } /** * @brief load_all_settings * Run the functions using the function array to load all the necessary settings. */ -void load_all_settings() { - for(int i=0;i<3;i++) { - (*load_functions[i])(); - } +void load_all_settings() +{ + for (int i = 0; i < 3; i++) + { + (*load_functions[i])(); + } } - /** * @brief is_mouse_button * Function to find out if the user mapped a keyboard key or mouse button @@ -107,7 +134,8 @@ void load_all_settings() { */ uint is_mouse_button(UINT vk) { - for (uint i=0;i<3;++i) { + for (uint i = 0; i < 3; ++i) + { if (MOUSE_BUTTONS[i] == vk) return 1; } diff --git a/src/settings.h b/src/settings.h index 70c1d06..1dc150c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -24,32 +24,31 @@ enum keys Y, RSHDR, LSHDR, - DPADDOWN, - DPADUP, - DPADRIGHT, - DPADLEFT + DPADDOWN, + DPADUP, + DPADRIGHT, + DPADLEFT }; } // namespace setting_keys extern QSettings *settings; inline QList server_settings = {"port"}; -//inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; +// inline QList keymaps = {"keymaps/A", "keymaps/B", "keymaps/X", "keymaps/Y", "keymaps/RT", "keymaps/LT"}; /** * @brief keymaps * a Qmap to map the keys in namespace to corresponding settings name in string format. */ inline QMap keymaps = {{setting_keys::keys::A, "keymaps/A"}, - {setting_keys::keys::B, "keymaps/B"}, - {setting_keys::keys::X, "keymaps/X"}, - {setting_keys::keys::Y, "keymaps/Y"}, + {setting_keys::keys::B, "keymaps/B"}, + {setting_keys::keys::X, "keymaps/X"}, + {setting_keys::keys::Y, "keymaps/Y"}, {setting_keys::keys::RSHDR, "keymaps/RT"}, {setting_keys::keys::LSHDR, "keymaps/LT"}, - {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, - {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, - {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, - {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}}; - + {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, + {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, + {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, + {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}}; void save_setting(QString key, QVariant value); QVariant load_setting(QString key); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index b9e9da6..504ae69 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -1,14 +1,13 @@ #include "settings_key_variables.h" int mouse_sensivity = 1000; // the mouse_sensivity or the cursor speed. -int port = 7878; // the port on which the server runs on. +int port = 7878; // the port on which the server runs on. /** * @brief GAMEPAD_BUTTONS * A map for the gamepad button and the corresponding input. */ -std::map GAMEPAD_BUTTONS = { - {GamepadButtons::GamepadButtons_Menu, TRIAL{VK_MENU, 0}}, +std::map GAMEPAD_BUTTONS = {{GamepadButtons::GamepadButtons_Menu, TRIAL{VK_MENU, 0}}, {GamepadButtons::GamepadButtons_View, TRIAL{VK_TAB, 0}}, {GamepadButtons::GamepadButtons_A, TRIAL{VK_RETURN, 0}}, {GamepadButtons::GamepadButtons_B, TRIAL{'B', 0}}, @@ -20,50 +19,48 @@ std::map GAMEPAD_BUTTONS = { {GamepadButtons::GamepadButtons_DPadRight, TRIAL{VK_RIGHT, 0}}, {GamepadButtons::GamepadButtons_LeftShoulder, TRIAL{VK_LBUTTON, 1}}, {GamepadButtons::GamepadButtons_RightShoulder, TRIAL{VK_NEXT, 0}}}; - // {GamepadButtons::GamepadButtons_LeftThumbstick, TRIAL{VK_LBUTTON, 1}}, - // {GamepadButtons::GamepadButtons_RightThumbstick, TRIAL{VK_NEXT, 0}}}; +// {GamepadButtons::GamepadButtons_LeftThumbstick, TRIAL{VK_LBUTTON, 1}}, +// {GamepadButtons::GamepadButtons_RightThumbstick, TRIAL{VK_NEXT, 0}}}; /** * @brief THUMBSTICK_KEYS * Maps the joystick movements. */ std::map THUMBSTICK_KEYS = { - {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, - {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, - {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, - {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; + {Thumbstick::LeftThumbstickUp, 'W'}, {Thumbstick::LeftThumbstickDown, 'S'}, + {Thumbstick::LeftThumbstickLeft, 'A'}, {Thumbstick::LeftThumbstickRight, 'D'}, + {Thumbstick::RightThumbstickUp, VK_UP}, {Thumbstick::RightThumbstickDown, VK_DOWN}, + {Thumbstick::RightThumbstickLeft, VK_LEFT}, {Thumbstick::RightThumbstickRight, VK_RIGHT}}; /** * @brief vk_maps * A std::map to map the virtual key codes to corresponding key names */ -std::map vk_maps = { - {VK_LBUTTON, "LMButton"}, - {VK_RBUTTON, "RMButton"}, - {VK_MBUTTON, "MMButton"}, - {VK_BACK, "BACKSPACE"}, - {VK_TAB, "TAB"}, - {VK_RETURN, "ENTER"}, - {VK_SHIFT, "SHIFT"}, - {VK_CONTROL, "CTRL"}, - {VK_CAPITAL, "CAPITAL"}, - {VK_ESCAPE, "ESCAPE"}, - {VK_SPACE, "SPACE"}, - {VK_PRIOR, "PageUP"}, - {VK_NEXT, "PageDOWN"}, - {VK_END, "END"}, - {VK_HOME, "HOME"}, - {VK_LEFT, "LEFT"}, - {VK_UP, "UP"}, - {VK_RIGHT, "RIGHT"}, - {VK_DOWN, "DOWN"}, - {VK_INSERT, "INS"}, - {VK_DELETE, "DEL"}, - {VK_OEM_PERIOD, "."}, - {VK_OEM_COMMA, ","}, - {VK_OEM_MINUS, "-"}, - {VK_OEM_PLUS, "+"} -}; +std::map vk_maps = {{VK_LBUTTON, "LMButton"}, + {VK_RBUTTON, "RMButton"}, + {VK_MBUTTON, "MMButton"}, + {VK_BACK, "BACKSPACE"}, + {VK_TAB, "TAB"}, + {VK_RETURN, "ENTER"}, + {VK_SHIFT, "SHIFT"}, + {VK_CONTROL, "CTRL"}, + {VK_CAPITAL, "CAPITAL"}, + {VK_ESCAPE, "ESCAPE"}, + {VK_SPACE, "SPACE"}, + {VK_PRIOR, "PageUP"}, + {VK_NEXT, "PageDOWN"}, + {VK_END, "END"}, + {VK_HOME, "HOME"}, + {VK_LEFT, "LEFT"}, + {VK_UP, "UP"}, + {VK_RIGHT, "RIGHT"}, + {VK_DOWN, "DOWN"}, + {VK_INSERT, "INS"}, + {VK_DELETE, "DEL"}, + {VK_OEM_PERIOD, "."}, + {VK_OEM_COMMA, ","}, + {VK_OEM_MINUS, "-"}, + {VK_OEM_PLUS, "+"}}; /** * @brief MOUSE_BUTTONS diff --git a/src/settings_key_variables.h b/src/settings_key_variables.h index e97a921..273879c 100644 --- a/src/settings_key_variables.h +++ b/src/settings_key_variables.h @@ -1,17 +1,18 @@ #pragma once #ifndef SETTINGS_KEY_VARIABLES_H #define SETTINGS_KEY_VARIABLES_H -#include #include +#include -#include #include "../VGP_Data_Exchange/C/GameButtons.h" +#include /** * @brief The TRIAL Struct * A structure to hold the button mappings. */ -struct TRIAL{ +struct TRIAL +{ WORD vk; uint is_mouse_key = 0; }; @@ -22,18 +23,18 @@ extern std::map GAMEPAD_BUTTONS; enum Thumbstick { - LeftThumbstickUp, - LeftThumbstickDown, - LeftThumbstickLeft, - LeftThumbstickRight, - RightThumbstickUp, - RightThumbstickDown, - RightThumbstickLeft, - RightThumbstickRight + LeftThumbstickUp, + LeftThumbstickDown, + LeftThumbstickLeft, + LeftThumbstickRight, + RightThumbstickUp, + RightThumbstickDown, + RightThumbstickLeft, + RightThumbstickRight }; extern std::map THUMBSTICK_KEYS; -extern std::map vk_maps; +extern std::map vk_maps; extern const QList MOUSE_BUTTONS; From 855b5f6d64d7cb23f92ce620d9605acb25b067fb Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 15 Dec 2023 22:36:40 +0530 Subject: [PATCH 29/31] Reset Preferences on Cancel --- src/preferences.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/preferences.cpp b/src/preferences.cpp index b4cdd97..65292ef 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -26,6 +26,7 @@ Preferences::Preferences(QWidget *parent) : QDialog(parent), ui(new Ui::Preferen mouse_sensivity / 100); // saving the new mouse sensivity change_key_inputs(); // changing and saving key maps }); + ui->buttonBox->connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=] { load_keys(); }); ui->formLayout->setSizeConstraint(QLayout::SetMinimumSize); ui->formLayout->setHorizontalSpacing(50); ui->formLayout->setVerticalSpacing(10); From b03f50f7f9dcabc2a8c659af810071bdea3ed3a5 Mon Sep 17 00:00:00 2001 From: franklin654 <77013274+franklin654@users.noreply.github.com> Date: Fri, 15 Dec 2023 23:53:15 +0530 Subject: [PATCH 30/31] Added the Menu Button and View Button --- res/icons.qrc | 2 ++ res/icons/icons8-xbox-menu-30.png | Bin 0 -> 363 bytes res/icons/icons8-xbox-windows-30.png | Bin 0 -> 442 bytes src/preferences.cpp | 18 ++++++++++++++ src/preferences.ui | 34 +++++++++++++++++++++++++++ src/settings.cpp | 6 +++++ src/settings.h | 8 +++++-- src/settings_key_variables.cpp | 3 ++- 8 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 res/icons/icons8-xbox-menu-30.png create mode 100644 res/icons/icons8-xbox-windows-30.png diff --git a/res/icons.qrc b/res/icons.qrc index ab095a4..0569267 100644 --- a/res/icons.qrc +++ b/res/icons.qrc @@ -14,5 +14,7 @@ icons/icons8-xbox-rt-30.png icons/icons8-xbox-x-30.png icons/icons8-xbox-y-30.png + icons/icons8-xbox-menu-30.png + icons/icons8-xbox-windows-30.png diff --git a/res/icons/icons8-xbox-menu-30.png b/res/icons/icons8-xbox-menu-30.png new file mode 100644 index 0000000000000000000000000000000000000000..8a3168c96449f92a7b711adc00ecf8009cf3be9d GIT binary patch literal 363 zcmV-x0hIoUP)1Gx5InVkdzJ;_W3F@E0x7f(V6LV1;Lx36xWe8WuDS*H+auSM=C<9lK)`3G{2n4{rD3E(yV9h76 z4NQSgATmg;nMh9ISOrGF(gK*)LaNYkg>C|O1%PQi1KYMxweZ~oG}ar?G(lH9y=huc z^69iOssI{mpo6xhDXIc5f!!?dv_fbk8fOiMynXrsyclEy4%0*C$dGVq>Pm;VK1e1F zYXlFHNtX`bn-ZmtWVZjr%mJ)^9|OG{o##AjRtDTLl)abptXr2-Ukj|`0UWqAS6XGj zC&`7~8o_(Xg=&D$YXFB?E@k2XzLJL1=|Pismh~@pDn2B>fR?UAu1)5m{%;t8M;rgu z6uaUJ`U-4e85zNw1DllrCCVG3OaK4?07*qoM6N<$g1jBGPXGV_ literal 0 HcmV?d00001 diff --git a/src/preferences.cpp b/src/preferences.cpp index 65292ef..6d4b015 100644 --- a/src/preferences.cpp +++ b/src/preferences.cpp @@ -103,6 +103,16 @@ void Preferences::change_key_inputs() GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].is_mouse_key = is_mouse_button(this->temp[ui->dleftmap->objectName()]); save_setting(keymaps[setting_keys::keys::DPADLEFT], this->temp[ui->dleftmap->objectName()]); + /*-----------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_View].vk = this->temp[ui->viewmap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_View].is_mouse_key = + is_mouse_button(this->temp[ui->viewmap->objectName()]); + save_setting(keymaps[setting_keys::keys::VIEW], this->temp[ui->viewmap->objectName()]); + /*-----------------------------------------------------------*/ + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Menu].vk = this->temp[ui->menumap->objectName()]; + GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Menu].is_mouse_key = + is_mouse_button(this->temp[ui->menumap->objectName()]); + save_setting(keymaps[setting_keys::keys::MENU], this->temp[ui->menumap->objectName()]); } /** @@ -176,6 +186,14 @@ void Preferences::load_keys() this->temp[ui->dleftmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_DPadLeft].vk; get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk, buffer, 256); this->ui->dleftmap->setText(QString(buffer)); + /*-----------------------------------------------------------*/ + this->temp[ui->viewmap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_View].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_View].vk, buffer, 256); + this->ui->viewmap->setText(QString(buffer)); + /*-----------------------------------------------------------*/ + this->temp[ui->menumap->objectName()] = GAMEPAD_BUTTONS[GamepadButtons::GamepadButtons_Menu].vk; + get_scan_code(GAMEPAD_BUTTONS[GamepadButtons_Menu].vk, buffer, 256); + this->ui->menumap->setText(QString(buffer)); } /** diff --git a/src/preferences.ui b/src/preferences.ui index a5b7621..a2ef5a2 100644 --- a/src/preferences.ui +++ b/src/preferences.ui @@ -348,6 +348,40 @@ + + + + + + + :/icons/icons8-xbox-menu-30.png + + + + + + + true + + + + + + + + + + :/icons/icons8-xbox-windows-30.png + + + + + + + true + + + diff --git a/src/settings.cpp b/src/settings.cpp index be4ad9b..ea92e7e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -111,6 +111,12 @@ void load_key_maps() // set the key mappings to the stored values GAMEPAD_BUTTONS[GamepadButtons_DPadLeft] = TRIAL{ (WORD)settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong(), is_mouse_button(settings->value(keymaps[DPADLEFT], GAMEPAD_BUTTONS[GamepadButtons_DPadLeft].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_View] = + TRIAL{(WORD)settings->value(keymaps[VIEW], GAMEPAD_BUTTONS[GamepadButtons_View].vk).toLongLong(), + is_mouse_button(settings->value(keymaps[VIEW], GAMEPAD_BUTTONS[GamepadButtons_View].vk).toLongLong())}; + GAMEPAD_BUTTONS[GamepadButtons_Menu] = + TRIAL{(WORD)settings->value(keymaps[MENU], GAMEPAD_BUTTONS[GamepadButtons_Menu].vk).toLongLong(), + is_mouse_button(settings->value(keymaps[MENU], GAMEPAD_BUTTONS[GamepadButtons_Menu].vk).toLongLong())}; } /** diff --git a/src/settings.h b/src/settings.h index 1dc150c..7abaae6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -27,7 +27,9 @@ enum keys DPADDOWN, DPADUP, DPADRIGHT, - DPADLEFT + DPADLEFT, + VIEW, + MENU }; } // namespace setting_keys @@ -48,7 +50,9 @@ inline QMap keymaps = {{setting_keys::keys::A, "key {setting_keys::keys::DPADDOWN, "keymaps/DPADDOWN"}, {setting_keys::keys::DPADUP, "keymaps/DPADUP"}, {setting_keys::keys::DPADRIGHT, "keymaps/DPADRIGHT"}, - {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}}; + {setting_keys::keys::DPADLEFT, "keymaps/DPADLEFT"}, + {setting_keys::keys::VIEW, "keymaps/VIEW"}, + {setting_keys::keys::MENU, "keymaps/MENU"}}; void save_setting(QString key, QVariant value); QVariant load_setting(QString key); diff --git a/src/settings_key_variables.cpp b/src/settings_key_variables.cpp index 504ae69..a70169d 100644 --- a/src/settings_key_variables.cpp +++ b/src/settings_key_variables.cpp @@ -60,7 +60,8 @@ std::map vk_maps = {{VK_LBUTTON, "LMButton"}, {VK_OEM_PERIOD, "."}, {VK_OEM_COMMA, ","}, {VK_OEM_MINUS, "-"}, - {VK_OEM_PLUS, "+"}}; + {VK_OEM_PLUS, "+"}, + {VK_MENU, "MENU"}}; /** * @brief MOUSE_BUTTONS From b78da903d2c3d306d3cda8d4eba2bf2dcc091cbe Mon Sep 17 00:00:00 2001 From: kitswas <90329875+kitswas@users.noreply.github.com> Date: Sat, 16 Dec 2023 09:47:44 +0530 Subject: [PATCH 31/31] Fixed submodules --- doxygen-awesome-css | 2 +- third-party-libs/QR-Code-generator | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doxygen-awesome-css b/doxygen-awesome-css index 40302ce..8fe5ac3 160000 --- a/doxygen-awesome-css +++ b/doxygen-awesome-css @@ -1 +1 @@ -Subproject commit 40302ce20f322d6243d758bb7a428818cddedd74 +Subproject commit 8fe5ac37f007d4a249f4469271a9ba6972a1393f diff --git a/third-party-libs/QR-Code-generator b/third-party-libs/QR-Code-generator index 49a66a2..720f62b 160000 --- a/third-party-libs/QR-Code-generator +++ b/third-party-libs/QR-Code-generator @@ -1 +1 @@ -Subproject commit 49a66a2b8bb8f8852fd2e1deb00b8672f5760139 +Subproject commit 720f62bddb7226106071d4728c292cb1df519ceb