Skip to content

Commit

Permalink
add tracking for mouse_press
Browse files Browse the repository at this point in the history
adding the mouse press filter to map the keys to mouse buttons
  • Loading branch information
franklin654 committed Aug 30, 2023
1 parent 11ea776 commit a2509f1
Showing 1 changed file with 251 additions and 1 deletion.
252 changes: 251 additions & 1 deletion src/preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <QPixmap>
#include <QLabel>
#include <QLayout>
#include <QKeySequence>
#include <QMouseEvent>
#include <QKeyEvent>
#include "winuser.h"
#include "windows.h"
Expand Down Expand Up @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<QMouseEvent*>(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) {
Expand All @@ -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<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" << Qt::endl;
valid = false;
}
if(valid)
ui->ddownmap->setText(QString(buffer));
}
}
else if(sender == ui->drightmap) {
if(event->type() == QEvent::KeyRelease) {
Expand All @@ -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<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" << Qt::endl;
valid = false;
}
if(valid)
ui->drightmap->setText(QString(buffer));
}
}
else if(sender == ui->dleftmap) {
if(event->type() == QEvent::KeyRelease) {
Expand All @@ -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<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" << Qt::endl;
valid = false;
}
if(valid)
ui->dleftmap->setText(QString(buffer));
}
}
return QWidget::eventFilter(sender,event);
}
Expand Down

0 comments on commit a2509f1

Please sign in to comment.