mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
客户端对接服务器多点触摸
This commit is contained in:
parent
b6669f88e1
commit
c69c0b0c25
5 changed files with 54 additions and 30 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue