diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp index 29d4d75..03d4667 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp @@ -4,6 +4,37 @@ #include "inputconvertgame.h" +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN + +#include +#include + +// restrict mouse into a window +static void restrictMouse(const int left, const int right, + const int top, const int bottom) +{ + RECT mainWinRect; // RECT is defined in + mainWinRect.left = static_cast(left); + mainWinRect.right = static_cast(right); + mainWinRect.top = static_cast(top); + mainWinRect.bottom = static_cast(bottom); + ClipCursor(&mainWinRect); // Windows API +} +static void freeMouse() +{ + ClipCursor(nullptr); +} + +#else +// dummy +static void restrictMouse(const int left, const int right, + const int top, const int bottom) +{} +static void freeMouse() +{} +#endif // _WINDOWS_ + #define CURSOR_POS_CHECK 50 InputConvertGame::InputConvertGame(Controller* controller) @@ -97,6 +128,11 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c case KeyMap::KMT_CLICK_TWICE: processKeyClick(node.clickTwice.keyNode.pos, true, false, from); return; + case KeyMap::KMT_DRAG: + processKeyDrag(node.drag.startPos, node.drag.endPos, from); + return; + default: + break; } } else { InputConvertNormal::keyEvent(from, frameSize, showSize); @@ -331,6 +367,17 @@ void InputConvertGame::processKeyClick(QPointF clickPos, bool clickTwice, bool s } } +void InputConvertGame::processKeyDrag(QPointF startPos, QPointF endPos, const QKeyEvent* from) +{ + if(QEvent::KeyPress == from->type()){ + int id = attachTouchID(from->key()); + sendTouchDownEvent(id, startPos); + sendTouchMoveEvent(id, endPos); + sendTouchUpEvent(id, endPos); + detachTouchID(from->key()); + } +} + bool InputConvertGame::processMouseClick(const QMouseEvent *from) { KeyMap::KeyMapNode& node = m_keyMap.getKeyMapNodeMouse(from->button()); @@ -451,7 +498,7 @@ bool InputConvertGame::switchGameMap() if (m_gameMap) { QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); } else { - mouseMoveStopTouch(); + mouseMoveStopTouch(); QGuiApplication::restoreOverrideCursor(); } return m_gameMap; diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h index 5313f7a..43d983c 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h @@ -41,6 +41,9 @@ protected: // click void processKeyClick(QPointF clickPos, bool clickTwice, bool switchMap, const QKeyEvent* from); + // drag + void processKeyDrag(QPointF startPos, QPointF endPos, const QKeyEvent* from); + // mouse bool processMouseClick(const QMouseEvent* from); bool processMouseMove(const QMouseEvent* from); diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp index 337adc4..c2b9086 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp @@ -313,12 +313,12 @@ void KeyMap::makeReverseMap() // ---- check and get of json item ---- -bool KeyMap::checkItemKey(const QJsonObject& node, QString name) +bool KeyMap::checkItemKey(const QJsonObject& node, const QString& name) { return node.contains(name) && node.value(name).isString(); } -bool KeyMap::checkItemPos(const QJsonObject& node, QString name) +bool KeyMap::checkItemPos(const QJsonObject& node, const QString& name) { if(node.contains(name) && node.value(name).isObject()){ QJsonObject pos = node.value(name).toObject(); @@ -328,23 +328,23 @@ bool KeyMap::checkItemPos(const QJsonObject& node, QString name) return false; } -bool KeyMap::checkItemDouble(const QJsonObject& node, QString name) +bool KeyMap::checkItemDouble(const QJsonObject& node, const QString& name) { return node.contains(name) && node.value(name).isDouble(); } -bool KeyMap::checkItemSwitchMap(const QJsonObject& node, QString name) +bool KeyMap::checkItemSwitchMap(const QJsonObject& node, const QString& name) { return !node.contains(name) || node.value(name).isBool(); } -KeyMap::KeyMapType KeyMap::getItemType(const QJsonObject& node, QString name) +KeyMap::KeyMapType KeyMap::getItemType(const QJsonObject& node, const QString& name) { QString value = node.value(name).toString(); return static_cast(m_metaEnumKeyMapType.keyToValue(value.toStdString().c_str())); } -QPair KeyMap::getItemKey(const QJsonObject& node, QString name) +QPair KeyMap::getItemKey(const QJsonObject& node, const QString& name) { QString value = node.value(name).toString(); int key = m_metaEnumKey.keyToValue(value.toStdString().c_str()); @@ -358,18 +358,18 @@ QPair KeyMap::getItemKey(const QJsonObject& node, QStri } } -QPointF KeyMap::getItemPos(const QJsonObject& node, QString name) +QPointF KeyMap::getItemPos(const QJsonObject& node, const QString& name) { QJsonObject pos = node.value(name).toObject(); return QPointF(pos.value("x").toDouble(), pos.value("y").toDouble()); } -double KeyMap::getItemNumber(const QJsonObject& node, QString name) +double KeyMap::getItemNumber(const QJsonObject& node, const QString& name) { return node.value(name).toDouble(); } -bool KeyMap::getItemSwitchMap(const QJsonObject& node, QString name) +bool KeyMap::getItemSwitchMap(const QJsonObject& node, const QString& name) { return node.value(name).toBool(false); } diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h index 450fb0a..155e24e 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h @@ -103,16 +103,16 @@ private: void makeReverseMap(); // parse json of the mapping script - bool checkItemKey(const QJsonObject& node, QString name="key"); - bool checkItemPos(const QJsonObject& node, QString name="pos"); - bool checkItemDouble(const QJsonObject& node, QString name); - bool checkItemSwitchMap(const QJsonObject& node, QString name="switchMap"); + bool checkItemKey(const QJsonObject& node, const QString& name="key"); + bool checkItemPos(const QJsonObject& node, const QString& name="pos"); + bool checkItemDouble(const QJsonObject& node, const QString& name); + bool checkItemSwitchMap(const QJsonObject& node, const QString& name="switchMap"); - KeyMapType getItemType(const QJsonObject& node, QString name="type"); - QPair getItemKey(const QJsonObject& node, QString name="key"); - QPointF getItemPos(const QJsonObject& node, QString name="pos"); - double getItemNumber(const QJsonObject& node, QString name); - bool getItemSwitchMap(const QJsonObject& node, QString name="switchMap"); + KeyMapType getItemType(const QJsonObject& node, const QString& name="type"); + QPair getItemKey(const QJsonObject& node, const QString& name="key"); + QPointF getItemPos(const QJsonObject& node, const QString& name="pos"); + double getItemNumber(const QJsonObject& node, const QString& name); + bool getItemSwitchMap(const QJsonObject& node, const QString& name="switchMap"); private: bool checkForClick(const QJsonObject& node);