diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp index 0e1c722..8ae3846 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "inputconvertgame.h" @@ -76,6 +77,27 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize &frameSize, c return; } + // small eyes + if (from->key() == m_keyMap.getMouseMoveMap().data.mouseMove.smallEyes.key) { + m_ctrlMouseMove.smallEyes = (QEvent::KeyPress == from->type()); + + if (QEvent::KeyPress == from->type()) { + m_processMouseMove = false; + int delay = 30; + QTimer::singleShot(delay, this, [this]() { mouseMoveStopTouch(); }); + QTimer::singleShot(delay * 2, this, [this]() { + mouseMoveStartTouch(nullptr); + m_processMouseMove = true; + }); + + stopMouseMoveTimer(); + } else { + mouseMoveStopTouch(); + mouseMoveStartTouch(nullptr); + } + return; + } + switch (node.type) { // 处理方向盘 case KeyMap::KMT_STEER_WHEEL: @@ -304,7 +326,6 @@ bool InputConvertGame::processMouseClick(const QMouseEvent *from) return false; } - qDebug() << "mouse event " << from->type(); if (QEvent::MouseButtonPress == from->type() || QEvent::MouseButtonDblClick == from->type()) { int id = attachTouchID(from->button()); sendTouchDownEvent(id, node.data.click.keyNode.pos); @@ -330,7 +351,7 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from) return true; } - if (!m_ctrlMouseMove.lastPos.isNull()) { + if (!m_ctrlMouseMove.lastPos.isNull() && m_processMouseMove) { QPointF distance = from->localPos() - m_ctrlMouseMove.lastPos; distance /= m_keyMap.getMouseMoveMap().data.mouseMove.speedRatio; @@ -340,10 +361,20 @@ bool InputConvertGame::processMouseMove(const QMouseEvent *from) m_ctrlMouseMove.lastConverPos.setX(m_ctrlMouseMove.lastConverPos.x() + distance.x() / m_showSize.width()); m_ctrlMouseMove.lastConverPos.setY(m_ctrlMouseMove.lastConverPos.y() + distance.y() / m_showSize.height()); - if (m_ctrlMouseMove.lastConverPos.x() < 0.1 || m_ctrlMouseMove.lastConverPos.x() > 0.8 || m_ctrlMouseMove.lastConverPos.y() < 0.1 - || m_ctrlMouseMove.lastConverPos.y() > 0.8) { - mouseMoveStopTouch(); - mouseMoveStartTouch(from); + if (m_ctrlMouseMove.lastConverPos.x() < 0.1 || m_ctrlMouseMove.lastConverPos.x() > 0.98 || m_ctrlMouseMove.lastConverPos.y() < 0.1 + || m_ctrlMouseMove.lastConverPos.y() > 0.98) { + if (m_ctrlMouseMove.smallEyes) { + m_processMouseMove = false; + int delay = 30; + QTimer::singleShot(delay, this, [this]() { mouseMoveStopTouch(); }); + QTimer::singleShot(delay * 2, this, [this]() { + mouseMoveStartTouch(nullptr); + m_processMouseMove = true; + }); + } else { + mouseMoveStopTouch(); + mouseMoveStartTouch(from); + } } sendTouchMoveEvent(getTouchID(Qt::ExtraButton24), m_ctrlMouseMove.lastConverPos); @@ -390,7 +421,8 @@ void InputConvertGame::mouseMoveStartTouch(const QMouseEvent *from) { Q_UNUSED(from) if (!m_ctrlMouseMove.touching) { - QPointF mouseMoveStartPos = m_keyMap.getMouseMoveMap().data.mouseMove.startPos; + QPointF mouseMoveStartPos + = m_ctrlMouseMove.smallEyes ? m_keyMap.getMouseMoveMap().data.mouseMove.smallEyes.pos : m_keyMap.getMouseMoveMap().data.mouseMove.startPos; int id = attachTouchID(Qt::ExtraButton24); sendTouchDownEvent(id, mouseMoveStartPos); m_ctrlMouseMove.lastConverPos = mouseMoveStartPos; diff --git a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h index c684717..662e9d1 100644 --- a/QtScrcpy/device/controller/inputconvert/inputconvertgame.h +++ b/QtScrcpy/device/controller/inputconvert/inputconvertgame.h @@ -66,6 +66,8 @@ private: int m_multiTouchID[MULTI_TOUCH_MAX_NUM] = { 0 }; KeyMap m_keyMap; + bool m_processMouseMove = true; + // steer wheel struct { @@ -86,6 +88,7 @@ private: QPointF lastPos = { 0.0, 0.0 }; bool touching = false; int timer = 0; + bool smallEyes = false; } m_ctrlMouseMove; }; diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp index 6cfb3c3..6c795da 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.cpp @@ -81,6 +81,39 @@ void KeyMap::loadKeyMap(const QString &json) if (checkItemDouble(startPos, "y")) { keyMapNode.data.mouseMove.startPos.setY(getItemDouble(startPos, "y")); } + + // small eyes + if (checkItemObject(mouseMoveMap, "smallEyes")) { + QJsonObject smallEyes = mouseMoveMap.value("smallEyes").toObject(); + if (!smallEyes.contains("type") || !smallEyes.value("type").isString()) { + errorString = QString("json error: smallEyes no find node type"); + goto parseError; + } + + // type just support KMT_CLICK + KeyMap::KeyMapType type = getItemKeyMapType(smallEyes, "type"); + if (KeyMap::KMT_CLICK != type) { + errorString = QString("json error: smallEyes just support KMT_CLICK"); + goto parseError; + } + + // safe check + if (!checkForClick(smallEyes)) { + errorString = QString("json error: smallEyes node format error"); + goto parseError; + } + + QPair key = getItemKey(smallEyes, "key"); + if (key.first == AT_INVALID) { + errorString = QString("json error: keyMapNodes node invalid key: %1").arg(smallEyes.value("key").toString()); + goto parseError; + } + + keyMapNode.data.mouseMove.smallEyes.type = key.first; + keyMapNode.data.mouseMove.smallEyes.key = key.second; + keyMapNode.data.mouseMove.smallEyes.pos = getItemPos(smallEyes, "pos"); + } + m_idxMouseMove = m_keyMapNodes.size(); m_keyMapNodes.push_back(keyMapNode); } diff --git a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h index b1fd321..1d4c555 100644 --- a/QtScrcpy/device/controller/inputconvert/keymap/keymap.h +++ b/QtScrcpy/device/controller/inputconvert/keymap/keymap.h @@ -78,6 +78,7 @@ public: { QPointF startPos = { 0.0, 0.0 }; int speedRatio = 1; + KeyNode smallEyes; } mouseMove; DATA() {} ~DATA() {} diff --git a/QtScrcpy/device/ui/videoform.cpp b/QtScrcpy/device/ui/videoform.cpp index e9d77ef..a8ff5b9 100644 --- a/QtScrcpy/device/ui/videoform.cpp +++ b/QtScrcpy/device/ui/videoform.cpp @@ -454,7 +454,7 @@ void VideoForm::onSwitchFullScreen() void VideoForm::updateFPS(quint32 fps) { - qDebug() << "FPS:" << fps; + //qDebug() << "FPS:" << fps; if (!m_fpsLabel) { return; } @@ -495,6 +495,14 @@ void VideoForm::mousePressEvent(QMouseEvent *event) } event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + + // debug keymap pos + if (event->button() == Qt::LeftButton) { + qreal x = event->localPos().x() / m_videoWidget->size().width(); + qreal y = event->localPos().y() / m_videoWidget->size().height(); + QString posTip = QString(R"("pos": {"x": %1, "y": %2})").arg(x).arg(y); + qInfo(posTip.toStdString().c_str()); + } } else { if (event->button() == Qt::LeftButton) { m_dragPosition = event->globalPos() - frameGeometry().topLeft(); @@ -556,6 +564,14 @@ void VideoForm::mouseDoubleClickEvent(QMouseEvent *event) if (event->button() == Qt::RightButton && m_device) { emit m_device->postBackOrScreenOn(); } + + if (m_videoWidget->geometry().contains(event->pos())) { + if (!m_device) { + return; + } + event->setLocalPos(m_videoWidget->mapFrom(this, event->localPos().toPoint())); + emit m_device->mouseEvent(event, m_videoWidget->frameSize(), m_videoWidget->size()); + } } void VideoForm::wheelEvent(QWheelEvent *event) diff --git a/QtScrcpy/devicemanage/devicemanage.cpp b/QtScrcpy/devicemanage/devicemanage.cpp index 6bcfcaa..7c47c81 100644 --- a/QtScrcpy/devicemanage/devicemanage.cpp +++ b/QtScrcpy/devicemanage/devicemanage.cpp @@ -43,15 +43,15 @@ bool DeviceManage::connectDevice(Device::DeviceParams params) connect(device, &Device::deviceDisconnect, this, &DeviceManage::onDeviceDisconnect); connect(device, &Device::controlStateChange, this, &DeviceManage::onControlStateChange); m_devices[params.serial] = device; + if (!m_script.isEmpty()) { + device->updateScript(m_script); + } return true; } void DeviceManage::updateScript(QString script) { - if (m_devices.isEmpty()) { - qWarning() << "no device connect!!!"; - return; - } + m_script = script; QMapIterator> i(m_devices); while (i.hasNext()) { i.next(); diff --git a/QtScrcpy/devicemanage/devicemanage.h b/QtScrcpy/devicemanage/devicemanage.h index 968a6e0..a01834d 100644 --- a/QtScrcpy/devicemanage/devicemanage.h +++ b/QtScrcpy/devicemanage/devicemanage.h @@ -40,6 +40,7 @@ private: private: QMap> m_devices; quint16 m_localPortStart = 27183; + QString m_script; }; #endif // DEVICEMANAGE_H diff --git a/README.md b/README.md index 1b18a95..3857370 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![Ubuntu](https://github.com/barry-ran/QtScrcpy/workflows/Ubuntu/badge.svg) ![license](https://img.shields.io/badge/license-Apache2.0-blue.svg) -![release](https://img.shields.io/badge/release-v1.3.0-brightgreen.svg) +![release](https://img.shields.io/github/v/release/barry-ran/QtScrcpy.svg) [中文介绍](README_zh.md) diff --git a/README_zh.md b/README_zh.md index be1ff0d..1ad471b 100644 --- a/README_zh.md +++ b/README_zh.md @@ -5,7 +5,7 @@ ![Ubuntu](https://github.com/barry-ran/QtScrcpy/workflows/Ubuntu/badge.svg) ![license](https://img.shields.io/badge/license-Apache2.0-blue.svg) -![release](https://img.shields.io/badge/release-v1.3.0-brightgreen.svg) +![release](https://img.shields.io/github/v/release/barry-ran/QtScrcpy.svg) [English introduction](README.md) diff --git a/docs/image/debug-keymap-pos.png b/docs/image/debug-keymap-pos.png new file mode 100644 index 0000000..1011ebe Binary files /dev/null and b/docs/image/debug-keymap-pos.png differ diff --git a/docs/按键映射说明.md b/docs/按键映射说明.md index fbf14f9..54fa1ad 100644 --- a/docs/按键映射说明.md +++ b/docs/按键映射说明.md @@ -10,6 +10,10 @@ - 按键映射中的坐标位置都是用相对位置表示的,屏幕的宽高都用1表示,例如屏幕的像素为1920x1080,那么坐标(0.5,0.5)则表示的是 以屏幕左上角为原点,像素坐标(1920,1080)*(0.5,0.5)=(960,540)的位置。 + + 或者鼠标左键单击时控制台会输出此时的pos,直接使用这个pos即可 + ![](image/debug-keymap-pos.png) + - 按键映射中的按键码是用Qt的枚举表示的,详细说明可以[参考Qt文档]( https://doc.qt.io/qt-5/qt.html )(搜索 The key names used by Qt. 可以快速定位)。 - 开发人员选项中打开如下两个设置,可以方便的观察触摸点的坐标: ![](image/显示指针位置.jpg) @@ -21,7 +25,8 @@ - mouseMoveMap:鼠标移动映射,鼠标的移动将被映射为以startPos为起点,以鼠标移动方向为移动方向的手指拖动操作(开启鼠标移动映射以后会隐藏鼠标,限制鼠标移动范围)。 一般在FPS手游中用来调整人物视野。 - startPos 手指拖动起始点 - - speedRatio 鼠标移动映射为手指拖动的比例,可以控制鼠标灵敏度 + - speedRatio 鼠标移动映射为手指拖动的比例,可以控制鼠标灵敏度,数值要大于0.00,数值越大,灵敏度越低 + - smallEyes 触发小眼睛的按键,按下此按键以后,鼠标的移动将被映射为以smallEyes.pos为起点,以鼠标移动方向为移动方向的手指拖动操作 - keyMapNodes 一般按键的映射,json数组,所有一般按键映射都放在这个数组中,将键盘的按键映射为普通的手指点击。 diff --git a/keymap/gameforpeace.json b/keymap/gameforpeace.json index 97d735a..3b46c4a 100644 --- a/keymap/gameforpeace.json +++ b/keymap/gameforpeace.json @@ -5,7 +5,17 @@ "x": 0.57, "y": 0.26 }, - "speedRatio": 8 + "smallEyes": { + "comment": "小眼睛", + "type": "KMT_CLICK", + "key": "Key_Alt", + "pos": { + "x": 0.8, + "y": 0.31 + }, + "switchMap": false + }, + "speedRatio": 10 }, "keyMapNodes": [ { @@ -102,16 +112,6 @@ }, "switchMap": false }, - { - "comment": "小眼睛", - "type": "KMT_CLICK", - "key": "Key_Alt", - "pos": { - "x": 0.8, - "y": 0.31 - }, - "switchMap": false - }, { "comment": "捡东西1", "type": "KMT_CLICK",