mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-16 05:51:28 +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;
|
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)
|
void ControlEvent::setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll)
|
||||||
{
|
{
|
||||||
m_data.scrollEvent.position = position;
|
m_data.scrollEvent.position = position;
|
||||||
|
@ -93,6 +100,11 @@ QByteArray ControlEvent::serializeData()
|
||||||
write32(buffer, m_data.mouseEvent.buttons);
|
write32(buffer, m_data.mouseEvent.buttons);
|
||||||
writePosition(buffer, m_data.mouseEvent.position);
|
writePosition(buffer, m_data.mouseEvent.position);
|
||||||
break;
|
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:
|
case CET_SCROLL:
|
||||||
writePosition(buffer, m_data.scrollEvent.position);
|
writePosition(buffer, m_data.scrollEvent.position);
|
||||||
write32(buffer, m_data.scrollEvent.hScroll);
|
write32(buffer, m_data.scrollEvent.hScroll);
|
||||||
|
|
|
@ -16,9 +16,10 @@ public:
|
||||||
enum ControlEventType {
|
enum ControlEventType {
|
||||||
CET_KEYCODE,
|
CET_KEYCODE,
|
||||||
CET_TEXT,
|
CET_TEXT,
|
||||||
CET_MOUSE,
|
CET_MOUSE,
|
||||||
CET_SCROLL,
|
CET_SCROLL,
|
||||||
CET_COMMAND,
|
CET_COMMAND,
|
||||||
|
CET_TOUCH,
|
||||||
};
|
};
|
||||||
|
|
||||||
ControlEvent(ControlEventType controlEventType);
|
ControlEvent(ControlEventType controlEventType);
|
||||||
|
@ -26,6 +27,10 @@ public:
|
||||||
void setKeycodeEventData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate);
|
void setKeycodeEventData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate);
|
||||||
void setTextEventData(QString text);
|
void setTextEventData(QString text);
|
||||||
void setMouseEventData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position);
|
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 setScrollEventData(QRect position, qint32 hScroll, qint32 vScroll);
|
||||||
void setCommandEventData(qint32 action);
|
void setCommandEventData(qint32 action);
|
||||||
|
|
||||||
|
@ -53,6 +58,11 @@ private:
|
||||||
AndroidMotioneventButtons buttons;
|
AndroidMotioneventButtons buttons;
|
||||||
QRect position;
|
QRect position;
|
||||||
} mouseEvent;
|
} mouseEvent;
|
||||||
|
struct {
|
||||||
|
quint32 id;
|
||||||
|
AndroidMotioneventAction action;
|
||||||
|
QRect position;
|
||||||
|
} touchEvent;
|
||||||
struct {
|
struct {
|
||||||
QRect position;
|
QRect position;
|
||||||
qint32 hScroll;
|
qint32 hScroll;
|
||||||
|
|
|
@ -24,43 +24,31 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int action = 0;
|
AndroidMotioneventAction action;
|
||||||
// pos
|
// pos
|
||||||
QPointF pos;
|
QPointF pos;
|
||||||
|
// id
|
||||||
|
int id = 0;
|
||||||
|
|
||||||
// pointer index
|
if (from->key() == Qt::Key_A) {
|
||||||
int pointerIndex = 0;
|
id = 0;
|
||||||
|
|
||||||
if (from->key() == Qt::Key_W) {
|
|
||||||
pointerIndex = 0x0000;
|
|
||||||
pos.setX(showSize.width() * 0.25f);
|
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);
|
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 {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
action |= pointerIndex;
|
|
||||||
|
|
||||||
// action
|
// action
|
||||||
switch (from->type()) {
|
switch (from->type()) {
|
||||||
case QEvent::KeyPress:
|
case QEvent::KeyPress:
|
||||||
if (from->key() == Qt::Key_W) {
|
action = AMOTION_EVENT_ACTION_DOWN;
|
||||||
action |= AMOTION_EVENT_ACTION_DOWN;
|
|
||||||
} else {
|
|
||||||
action |= AMOTION_EVENT_ACTION_POINTER_DOWN;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case QEvent::KeyRelease:
|
case QEvent::KeyRelease:
|
||||||
if (from->key() == Qt::Key_W) {
|
action = AMOTION_EVENT_ACTION_UP;
|
||||||
action |= AMOTION_EVENT_ACTION_UP;
|
|
||||||
} else {
|
|
||||||
action |= AMOTION_EVENT_ACTION_POINTER_UP;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
@ -71,14 +59,27 @@ void InputConvertGame::keyEvent(const QKeyEvent *from, const QSize& frameSize, c
|
||||||
pos.setY(pos.y() * frameSize.height() / showSize.height());
|
pos.setY(pos.y() * frameSize.height() / showSize.height());
|
||||||
|
|
||||||
// set data
|
// set data
|
||||||
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_MOUSE);
|
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_TOUCH);
|
||||||
if (!controlEvent) {
|
if (!controlEvent) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
controlEvent->setMouseEventData((AndroidMotioneventAction)action, AMOTION_EVENT_BUTTON_PRIMARY, QRect(pos.toPoint(), frameSize));
|
controlEvent->setTouchEventData(id, action, QRect(pos.toPoint(), frameSize));
|
||||||
sendControlEvent(controlEvent);
|
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()) {
|
if (QEvent::KeyPress == from->type()) {
|
||||||
ControlEvent* controlEvent2 = new ControlEvent(ControlEvent::CET_MOUSE);
|
ControlEvent* controlEvent2 = new ControlEvent(ControlEvent::CET_MOUSE);
|
||||||
if (!controlEvent2) {
|
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));
|
controlEvent2->setMouseEventData((AndroidMotioneventAction)action, AMOTION_EVENT_BUTTON_PRIMARY, QRect(pos.toPoint(), frameSize));
|
||||||
sendControlEvent(controlEvent2);
|
sendControlEvent(controlEvent2);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -119,12 +119,12 @@ void VideoForm::wheelEvent(QWheelEvent *event)
|
||||||
|
|
||||||
void VideoForm::keyPressEvent(QKeyEvent *event)
|
void VideoForm::keyPressEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
qDebug() << "keyPressEvent" << event->isAutoRepeat();
|
//qDebug() << "keyPressEvent" << event->isAutoRepeat();
|
||||||
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
|
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
void VideoForm::keyReleaseEvent(QKeyEvent *event)
|
||||||
{
|
{
|
||||||
qDebug() << "keyReleaseEvent" << event->isAutoRepeat();
|
//qDebug() << "keyReleaseEvent" << event->isAutoRepeat();
|
||||||
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
|
m_inputConvert.keyEvent(event, ui->videoWidget->frameSize(), size());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue