diff --git a/src/inputcontrol/controlevent.cpp b/src/inputcontrol/controlevent.cpp index ac806b9..99c8a79 100644 --- a/src/inputcontrol/controlevent.cpp +++ b/src/inputcontrol/controlevent.cpp @@ -29,6 +29,13 @@ void ControlEvent::setMouseEventData(AndroidMotioneventAction action, AndroidMot m_data.mouseEvent.position = position; } +void ControlEvent::setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position) +{ + m_data.touchEvent.action = action; + m_data.touchEvent.id = id; + m_data.touchEvent.position = position; +} + void ControlEvent::setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll) { m_data.scrollEvent.position = position; @@ -93,6 +100,11 @@ QByteArray ControlEvent::serializeData() write32(buffer, m_data.mouseEvent.buttons); writePosition(buffer, m_data.mouseEvent.position); break; + case CET_TOUCH: + buffer.putChar(m_data.touchEvent.id); + buffer.putChar(m_data.touchEvent.action); + writePosition(buffer, m_data.touchEvent.position); + break; case CET_SCROLL: writePosition(buffer, m_data.scrollEvent.position); write32(buffer, m_data.scrollEvent.hScroll); diff --git a/src/inputcontrol/controlevent.h b/src/inputcontrol/controlevent.h index 4bd827f..7629854 100644 --- a/src/inputcontrol/controlevent.h +++ b/src/inputcontrol/controlevent.h @@ -16,9 +16,10 @@ public: enum ControlEventType { CET_KEYCODE, CET_TEXT, - CET_MOUSE, + CET_MOUSE, CET_SCROLL, CET_COMMAND, + CET_TOUCH, }; ControlEvent(ControlEventType controlEventType); @@ -26,6 +27,10 @@ public: void setKeycodeEventData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate); void setTextEventData(QString text); void setMouseEventData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position); + // id 代表一个触摸点,最多支持10个触摸点[0,9] + // action 只能是AMOTION_EVENT_ACTION_DOWN,AMOTION_EVENT_ACTION_UP,AMOTION_EVENT_ACTION_MOVE + // position action动作对应的位置 + void setTouchEventData(quint32 id, AndroidMotioneventAction action, QRect position); void setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll); void setCommandEventData(qint32 action); @@ -53,6 +58,11 @@ private: AndroidMotioneventButtons buttons; QRect position; } mouseEvent; + struct { + quint32 id; + AndroidMotioneventAction action; + QRect position; + } touchEvent; struct { QRect position; qint32 hScroll; diff --git a/src/inputcontrol/inputconvertgame.cpp b/src/inputcontrol/inputconvertgame.cpp index b7662cc..29258d7 100644 --- a/src/inputcontrol/inputconvertgame.cpp +++ b/src/inputcontrol/inputconvertgame.cpp @@ -24,43 +24,31 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c return; } - int action = 0; + AndroidMotioneventAction action; // pos QPointF pos; + // id + int id = 0; - // pointer index - int pointerIndex = 0; - - if (from->key() == Qt::Key_W) { - pointerIndex = 0x0000; + if (from->key() == Qt::Key_A) { + id = 0; pos.setX(showSize.width() * 0.25f); - pos.setY(showSize.height() * 0.5f); - } else if (from->key() == Qt::Key_D) { - pointerIndex = 0x0100; - pos.setX(showSize.width() * 0.5f); pos.setY(showSize.height() * 0.25f); + } else if (from->key() == Qt::Key_S) { + id = 1; + pos.setX(showSize.width() * 0.35f); + pos.setY(showSize.height() * 0.35f); } else { return; } - - action |= pointerIndex; - // action switch (from->type()) { case QEvent::KeyPress: - if (from->key() == Qt::Key_W) { - action |= AMOTION_EVENT_ACTION_DOWN; - } else { - action |= AMOTION_EVENT_ACTION_POINTER_DOWN; - } + action = AMOTION_EVENT_ACTION_DOWN; break; case QEvent::KeyRelease: - if (from->key() == Qt::Key_W) { - action |= AMOTION_EVENT_ACTION_UP; - } else { - action |= AMOTION_EVENT_ACTION_POINTER_UP; - } + action = AMOTION_EVENT_ACTION_UP; break; default: return; @@ -71,14 +59,27 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c pos.setY(pos.y() * frameSize.height() / showSize.height()); // set data - ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_MOUSE); + ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_TOUCH); if (!controlEvent) { return; - } - controlEvent->setMouseEventData((AndroidMotioneventAction)action, AMOTION_EVENT_BUTTON_PRIMARY, QRect(pos.toPoint(), frameSize)); + } + controlEvent->setTouchEventData(id, action, QRect(pos.toPoint(), frameSize)); sendControlEvent(controlEvent); - return; + if (QEvent::KeyPress == from->type() && from->key() == Qt::Key_S) { + // set data + ControlEvent* controlEvent2 = new ControlEvent(ControlEvent::CET_TOUCH); + if (!controlEvent2) { + return; + } + pos.setX(pos.x() + 50); + pos.setY(pos.y() + 50); + controlEvent2->setTouchEventData(id, AMOTION_EVENT_ACTION_MOVE, QRect(pos.toPoint(), frameSize)); + sendControlEvent(controlEvent2); + } + + return; +/* if (QEvent::KeyPress == from->type()) { ControlEvent* controlEvent2 = new ControlEvent(ControlEvent::CET_MOUSE); if (!controlEvent2) { @@ -90,4 +91,5 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c controlEvent2->setMouseEventData((AndroidMotioneventAction)action, AMOTION_EVENT_BUTTON_PRIMARY, QRect(pos.toPoint(), frameSize)); sendControlEvent(controlEvent2); } + */ } diff --git a/src/scrcpy-server.jar b/src/scrcpy-server.jar index e14dbb8..3dcf27d 100644 Binary files a/src/scrcpy-server.jar and b/src/scrcpy-server.jar differ diff --git a/src/videoform.cpp b/src/videoform.cpp index 955a6b0..1a31d7f 100644 --- a/src/videoform.cpp +++ b/src/videoform.cpp @@ -119,12 +119,12 @@ void VideoForm::wheelEvent(QWheelEvent *event) void VideoForm::keyPressEvent(QKeyEvent *event) { - qDebug() << "keyPressEvent" << event->isAutoRepeat(); + //qDebug() << "keyPressEvent" << event->isAutoRepeat(); m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size()); } void VideoForm::keyReleaseEvent(QKeyEvent *event) { - qDebug() << "keyReleaseEvent" << event->isAutoRepeat(); + //qDebug() << "keyReleaseEvent" << event->isAutoRepeat(); m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size()); }