-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user editable key maps #5
Conversation
franklin654
commented
Aug 26, 2023
- changed the Cmakelist to remove unnecessary space.
- added the functions to load and save key maps.
- created and installed event filters to pick up user input for custom key maps
changed all static hard coded values to variables and included them in a separate folder
removed extra spaces
icons for preference buttons
added image files for button icons
added the functions and maps required to dynamically change key maps as defined by the user
fixing the bug that occurs when mapping to numbers, adding the icon files qt resource
adding the mouse press filter to map the keys to mouse buttons
There's not a single line of documentation accompanying the code changes. |
Co-authored-by: kitswas <[email protected]>
Co-authored-by: kitswas <[email protected]>
fixing the broken include guard, removed the redundant functions, removed the qt::endl, fixed the typo in config file name
described all the functions, their parameters and what the functions return.
@franklin654 Before: After: Everything seems to be squished. And the UI no longer scales properly with the window. Also, kindly read what the QSizePolicies mean. |
And a bit of clarification about the documentation comments. Something like
ends up as: So:
Here's what I would write for this function:
See. Looks nicer already. |
This reverts commit 9a29227.
Currently, there is no option to map a button to mouse input. |
We should support:
Here's what we could have in place of the The current The mouse input type could be presented in a Edit: A button cannot be mapped to mouse move. |
The Analogue Thumbsticks are missing. For each thumbstick, we should be able to
|
src/preferences.cpp
Outdated
QKeyEvent* key_press = static_cast<QKeyEvent*>(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<QMouseEvent*>(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; | ||
} | ||
if(valid) | ||
ui->ddownmap->setText(QString(buffer)); | ||
} | ||
} | ||
else if(sender == ui->drightmap) { | ||
if(event->type() == QEvent::KeyRelease) { | ||
QKeyEvent* key_press = static_cast<QKeyEvent*>(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<QMouseEvent*>(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<QKeyEvent*>(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<QMouseEvent*>(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)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much of this code is simply duplicated with different variables.
This must change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend creating a new component for keyinput (like the one discussed) and moving this logic there.
decreasing the length of code using for loops and iterators. and removing excess if statements and variables, changing the order of key maps.
@franklin654 Are you still working on this? |
Yes Just started today again. |
src/preferences.cpp
Outdated
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); | ||
} | ||
else { | ||
strncpy(a, vk_maps[vk], size); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@franklin654
There was a bug in the code using strncpy
that was causing the application to crash.
Did you fix that?
Please debug and verify.
See Preferences::get_scan_code()
in the file src/preferences.cpp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I replaced the strncpy with strncpy_s with buffer size checks just haven't commited yet there are other changes that need to be done in preferences.cpp
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.
Fixing some of the code smells Sound Cloud suggested that are fixable.
Changing the Documentation according to your suggestions. kitswas#5 (comment)
@franklin654 ./code-lint.ps1 |
|