Skip to content

Commit

Permalink
Format code with clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Sep 16, 2021
1 parent 3ac78b5 commit d96969c
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 171 deletions.
70 changes: 25 additions & 45 deletions src/eventhandlers/winsendinputeventhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,21 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <qt_windows.h>
#include <cmath>
#include <qt_windows.h>

#include "winsendinputeventhandler.h"
#include <winextras.h>
#include <antkeymapper.h>
#include <winextras.h>

WinSendInputEventHandler::WinSendInputEventHandler(QObject *parent) :
BaseEventHandler(parent)
WinSendInputEventHandler::WinSendInputEventHandler(QObject *parent)
: BaseEventHandler(parent)
{
}

bool WinSendInputEventHandler::init()
{
return true;
}
bool WinSendInputEventHandler::init() { return true; }

bool WinSendInputEventHandler::cleanup()
{
return true;
}
bool WinSendInputEventHandler::cleanup() { return true; }

void WinSendInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
{
Expand All @@ -47,7 +41,7 @@ void WinSendInputEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool press
int tempflags = extended ? KEYEVENTF_EXTENDEDKEY : 0;

temp[0].type = INPUT_KEYBOARD;
//temp[0].ki.wScan = MapVirtualKey(code, MAPVK_VK_TO_VSC);
// temp[0].ki.wScan = MapVirtualKey(code, MAPVK_VK_TO_VSC);
temp[0].ki.wScan = scancode;
temp[0].ki.time = 0;
temp[0].ki.dwExtraInfo = 0;
Expand All @@ -66,41 +60,33 @@ void WinSendInputEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool pr
if (code == 1)
{
temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
}
else if (code == 2)
} else if (code == 2)
{
temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
}
else if (code == 3)
} else if (code == 3)
{
temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
}
else if (code == 4)
} else if (code == 4)
{
temp[0].mi.dwFlags = MOUSEEVENTF_WHEEL;
temp[0].mi.mouseData = pressed ? WHEEL_DELTA : 0;
}
else if (code == 5)
} else if (code == 5)
{
temp[0].mi.dwFlags = MOUSEEVENTF_WHEEL;
temp[0].mi.mouseData = pressed ? -WHEEL_DELTA : 0;
}
else if (code == 6)
} else if (code == 6)
{
temp[0].mi.dwFlags = 0x01000;
temp[0].mi.mouseData = pressed ? -WHEEL_DELTA : 0;
}
else if (code == 7)
} else if (code == 7)
{
temp[0].mi.dwFlags = 0x01000;
temp[0].mi.mouseData = pressed ? WHEEL_DELTA : 0;
}
else if (code == 8)
} else if (code == 8)
{
temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
temp[0].mi.mouseData = XBUTTON1;
}
else if (code == 9)
} else if (code == 9)
{
temp[0].mi.dwFlags = pressed ? MOUSEEVENTF_XDOWN : MOUSEEVENTF_XUP;
temp[0].mi.mouseData = XBUTTON2;
Expand All @@ -114,24 +100,18 @@ void WinSendInputEventHandler::sendMouseEvent(int xDis, int yDis)
INPUT temp[1] = {};
temp[0].type = INPUT_MOUSE;
temp[0].mi.mouseData = 0;
temp[0].mi.dwFlags = MOUSEEVENTF_MOVE;
temp[0].mi.dwFlags = MOUSEEVENTF_MOVE;
temp[0].mi.dx = xDis;
temp[0].mi.dy = yDis;
SendInput(1, temp, sizeof(INPUT));
}

QString WinSendInputEventHandler::getName()
{
return QString("SendInput");
}
QString WinSendInputEventHandler::getName() { return QString("SendInput"); }

QString WinSendInputEventHandler::getIdentifier()
{
return QString("sendinput");
}
QString WinSendInputEventHandler::getIdentifier() { return QString("sendinput"); }

void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis,
unsigned int width, unsigned int height)
void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width,
unsigned int height)
{
if (width > 0 && height > 0)
{
Expand All @@ -140,8 +120,8 @@ void WinSendInputEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned
temp[0].mi.mouseData = 0;
temp[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;

int fx = ceil(xDis * (65535.0/static_cast<double>(width)));
int fy = ceil(yDis * (65535.0/static_cast<double>(height)));
int fx = ceil(xDis * (65535.0 / static_cast<double>(width)));
int fy = ceil(yDis * (65535.0 / static_cast<double>(height)));
temp[0].mi.dx = fx;
temp[0].mi.dy = fy;
SendInput(1, temp, sizeof(INPUT));
Expand All @@ -154,9 +134,9 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext)

if (mapper && mapper->getKeyMapper())
{
QtWinKeyMapper *keymapper = static_cast<QtWinKeyMapper*>(mapper->getKeyMapper());
QtWinKeyMapper *keymapper = static_cast<QtWinKeyMapper *>(mapper->getKeyMapper());

for (int i=0; i < maintext.size(); i++)
for (int i = 0; i < maintext.size(); i++)
{
QtWinKeyMapper::charKeyInformation temp = keymapper->getCharKeyInformation(maintext.at(i));
QList<unsigned int> tempList;
Expand Down Expand Up @@ -214,7 +194,7 @@ void WinSendInputEventHandler::sendTextEntryEvent(QString maintext)
tempiter.toBack();
j = 0;
memset(tempBuffer, 0, sizeof(tempBuffer));
//INPUT tempBuffer2[tempList.size()] = {0};
// INPUT tempBuffer2[tempList.size()] = {0};
while (tempiter.hasPrevious())
{
unsigned int tempcode = tempiter.previous();
Expand Down
11 changes: 4 additions & 7 deletions src/eventhandlers/winsendinputeventhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,26 @@

#include <joybuttonslot.h>


class WinSendInputEventHandler : public BaseEventHandler
{
Q_OBJECT
public:
public:
explicit WinSendInputEventHandler(QObject *parent = 0);

virtual bool init();
virtual bool cleanup();
virtual void sendKeyboardEvent(JoyButtonSlot *slot, bool pressed);
virtual void sendMouseButtonEvent(JoyButtonSlot *slot, bool pressed);
virtual void sendMouseEvent(int xDis, int yDis);
virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis,
unsigned int width, unsigned int height);
virtual void sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width, unsigned int height);
virtual void sendTextEntryEvent(QString maintext);

virtual QString getName();
virtual QString getIdentifier();

signals:

public slots:
signals:

public slots:
};

#endif // WINSENDINPUTEVENTHANDLER_H
90 changes: 33 additions & 57 deletions src/eventhandlers/winvmultieventhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
*/

//#include <QDebug>
#include <cmath>
#include <qt_windows.h>
#include <winextras.h>
#include <cmath>

#include "winvmultieventhandler.h"

#include <qtvmultikeymapper.h>

WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent) :
BaseEventHandler(parent),
sendInputHandler(this)
WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent)
: BaseEventHandler(parent)
, sendInputHandler(this)
{
vmulti = 0;
mouseButtons = 0;
Expand All @@ -40,10 +40,7 @@ WinVMultiEventHandler::WinVMultiEventHandler(QObject *parent) :
nativeKeyMapper = 0;
}

WinVMultiEventHandler::~WinVMultiEventHandler()
{
cleanup();
}
WinVMultiEventHandler::~WinVMultiEventHandler() { cleanup(); }

bool WinVMultiEventHandler::init()
{
Expand Down Expand Up @@ -109,10 +106,9 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
if (code <= 0x65)
{
pendingKey = code;
}
else if (code >= 0xE0 && code <= 0xE7)
} else if (code >= 0xE0 && code <= 0xE7)
{
//pendingShift = 1 << (code - 0xE0);
// pendingShift = 1 << (code - 0xE0);
if (nativeKeyMapper)
{
unsigned int nativeKey = nativeKeyMapper->returnVirtualKey(slot->getSlotCodeAlias());
Expand All @@ -122,8 +118,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
useSendInput = true;
}
}
}
else if (code > QtVMultiKeyMapper::consumerUsagePagePrefix)
} else if (code > QtVMultiKeyMapper::consumerUsagePagePrefix)
{
if (nativeKeyMapper)
{
Expand Down Expand Up @@ -186,16 +181,15 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
}
*/

}
else if (code > 0x65)
} else if (code > 0x65)
{
if (nativeKeyMapper)
{
unsigned int nativeKey = nativeKeyMapper->returnVirtualKey(slot->getSlotCodeAlias());
if (nativeKey > 0)
{
tempSendInputSlot.setSlotCode(nativeKey);
//sendInputHandler.sendKeyboardEvent(tempslot, pressed);
// sendInputHandler.sendKeyboardEvent(tempslot, pressed);
useSendInput = true;
}
}
Expand Down Expand Up @@ -236,8 +230,7 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
keyboardKeys.replace(index, pendingKey);
}
}
}
else
} else
{
shiftKeys = shiftKeys ^ pendingShift;
multiKeys = multiKeys ^ pendingMultimedia;
Expand All @@ -262,8 +255,8 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)
}
*/

//qDebug() << "CURRENT: " << trying.join(",");
//qDebug() << keykeyArray;
// qDebug() << "CURRENT: " << trying.join(",");
// qDebug() << keykeyArray;

if (pendingKey > 0x0)
{
Expand All @@ -272,10 +265,9 @@ void WinVMultiEventHandler::sendKeyboardEvent(JoyButtonSlot *slot, bool pressed)

if (pendingMultimedia > 0 || pendingExtra > 0)
{
//vmulti_update_keyboard_enhanced(vmulti, multiKeys, extraKeys);
// vmulti_update_keyboard_enhanced(vmulti, multiKeys, extraKeys);
}
}
else
} else
{
sendInputHandler.sendKeyboardEvent(&tempSendInputSlot, pressed);
useSendInput = false;
Expand All @@ -294,24 +286,19 @@ void WinVMultiEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool press
if (code == 1)
{
pendingButton = 0x01;
}
else if (code == 2)
} else if (code == 2)
{
pendingButton = 0x04;
}
else if (code == 3)
} else if (code == 3)
{
pendingButton = 0x02;
}
else if (code == 4)
} else if (code == 4)
{
pendingWheel = pressed ? 1 : 0;
}
else if (code == 5)
} else if (code == 5)
{
pendingWheel = pressed ? -1 : 0;
}
else if (code >= 6 && code <= 9)
} else if (code >= 6 && code <= 9)
{
useSendInput = true;
}
Expand Down Expand Up @@ -339,32 +326,30 @@ void WinVMultiEventHandler::sendMouseButtonEvent(JoyButtonSlot *slot, bool press
if (pressed)
{
mouseButtons = mouseButtons | pendingButton;
vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel);//, pendingHWheel);
}
else
vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel); //, pendingHWheel);
} else
{
mouseButtons = mouseButtons ^ pendingButton;
vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel);//, pendingHWheel);
vmulti_update_relative_mouse(vmulti, mouseButtons, 0, 0, pendingWheel); //, pendingHWheel);
}
}
else
} else
{
sendInputHandler.sendMouseButtonEvent(slot, pressed);
}
}

void WinVMultiEventHandler::sendMouseEvent(int xDis, int yDis)
{
vmulti_update_relative_mouse(vmulti, mouseButtons, xDis, yDis, 0);//, 0);
vmulti_update_relative_mouse(vmulti, mouseButtons, xDis, yDis, 0); //, 0);
}

void WinVMultiEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis,
unsigned int width, unsigned int height)
void WinVMultiEventHandler::sendMouseSpringEvent(unsigned int xDis, unsigned int yDis, unsigned int width,
unsigned int height)
{
if (width > 0 && height > 0)
{
int fx = ceil(xDis * (32767.0/static_cast<double>(width)));
int fy = ceil(yDis * (32767.0/static_cast<double>(height)));
int fx = ceil(xDis * (32767.0 / static_cast<double>(width)));
int fy = ceil(yDis * (32767.0 / static_cast<double>(height)));
sendMouseAbsEvent(fx, fy, -1);
}
}
Expand All @@ -373,23 +358,14 @@ void WinVMultiEventHandler::sendMouseAbsEvent(int xDis, int yDis, int screen)
{
Q_UNUSED(screen);

vmulti_update_mouse(vmulti, mouseButtons, xDis, yDis, 0);//, 0);
vmulti_update_mouse(vmulti, mouseButtons, xDis, yDis, 0); //, 0);
}

/*
* TODO: Implement text event using information from QtWinKeyMapper.
*/
void WinVMultiEventHandler::sendTextEntryEvent(QString maintext)
{
sendInputHandler.sendTextEntryEvent(maintext);
}
void WinVMultiEventHandler::sendTextEntryEvent(QString maintext) { sendInputHandler.sendTextEntryEvent(maintext); }

QString WinVMultiEventHandler::getName()
{
return QString("Vmulti");
}
QString WinVMultiEventHandler::getName() { return QString("Vmulti"); }

QString WinVMultiEventHandler::getIdentifier()
{
return QString("vmulti");
}
QString WinVMultiEventHandler::getIdentifier() { return QString("vmulti"); }
Loading

0 comments on commit d96969c

Please sign in to comment.