mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-03 14:18:45 +00:00
fix:输入文本的bug
This commit is contained in:
parent
4109c4724d
commit
b29c4fae6e
6 changed files with 25 additions and 16 deletions
|
@ -41,7 +41,7 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Wireless</string>
|
<string>Wireless</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_4" columnstretch="2,0,0,1,0">
|
<layout class="QGridLayout" name="gridLayout_4" columnstretch="2,0,0,1,2">
|
||||||
<item row="3" column="2">
|
<item row="3" column="2">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
#include "controlevent.h"
|
#include "controlevent.h"
|
||||||
|
|
||||||
#define TEXT_MAX_CHARACTER_LENGTH 300
|
|
||||||
|
|
||||||
ControlEvent::ControlEvent(ControlEventType controlEventType)
|
ControlEvent::ControlEvent(ControlEventType controlEventType)
|
||||||
: QScrcpyEvent(Control)
|
: QScrcpyEvent(Control)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +17,14 @@ void ControlEvent::setKeycodeEventData(AndroidKeyeventAction action, AndroidKeyc
|
||||||
|
|
||||||
void ControlEvent::setTextEventData(QString text)
|
void ControlEvent::setTextEventData(QString text)
|
||||||
{
|
{
|
||||||
m_data.textEvent.text = text;
|
// write length (2 byte) + date (non nul-terminated)
|
||||||
|
if (TEXT_MAX_CHARACTER_LENGTH < text.length()) {
|
||||||
|
// injecting a text takes time, so limit the text length
|
||||||
|
text = text.left(TEXT_MAX_CHARACTER_LENGTH);
|
||||||
|
}
|
||||||
|
QByteArray tmp = text.toUtf8();
|
||||||
|
memset(m_data.textEvent.text, 0, sizeof (m_data.textEvent.text));
|
||||||
|
memcpy(m_data.textEvent.text, tmp.data(), tmp.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ControlEvent::setMouseEventData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position)
|
void ControlEvent::setMouseEventData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, QRect position)
|
||||||
|
@ -85,14 +90,8 @@ QByteArray ControlEvent::serializeData()
|
||||||
break;
|
break;
|
||||||
case CET_TEXT:
|
case CET_TEXT:
|
||||||
{
|
{
|
||||||
// write length (2 byte) + date (non nul-terminated)
|
write16(buffer, strlen(m_data.textEvent.text));
|
||||||
if (TEXT_MAX_CHARACTER_LENGTH < m_data.textEvent.text.length()) {
|
buffer.write(m_data.textEvent.text, strlen(m_data.textEvent.text));
|
||||||
// injecting a text takes time, so limit the text length
|
|
||||||
m_data.textEvent.text = m_data.textEvent.text.left(TEXT_MAX_CHARACTER_LENGTH);
|
|
||||||
}
|
|
||||||
QByteArray tmp = m_data.textEvent.text.toUtf8();
|
|
||||||
write16(buffer, tmp.length());
|
|
||||||
buffer.write(tmp.data(), tmp.length());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CET_MOUSE:
|
case CET_MOUSE:
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "keycodes.h"
|
#include "keycodes.h"
|
||||||
|
|
||||||
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
|
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
|
||||||
|
|
||||||
|
#define TEXT_MAX_CHARACTER_LENGTH 300
|
||||||
// ControlEvent
|
// ControlEvent
|
||||||
class ControlEvent : public QScrcpyEvent
|
class ControlEvent : public QScrcpyEvent
|
||||||
{
|
{
|
||||||
|
@ -52,7 +54,7 @@ private:
|
||||||
AndroidMetastate metastate;
|
AndroidMetastate metastate;
|
||||||
} keycodeEvent;
|
} keycodeEvent;
|
||||||
struct {
|
struct {
|
||||||
QString text;
|
char text[TEXT_MAX_CHARACTER_LENGTH + 1];
|
||||||
} textEvent;
|
} textEvent;
|
||||||
struct {
|
struct {
|
||||||
AndroidMotioneventAction action;
|
AndroidMotioneventAction action;
|
||||||
|
|
|
@ -259,6 +259,16 @@ void VideoForm::postTurnOn()
|
||||||
m_inputConvert.sendControlEvent(controlEvent);
|
m_inputConvert.sendControlEvent(controlEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VideoForm::postTextInput(const QString& text)
|
||||||
|
{
|
||||||
|
ControlEvent* controlEvent = new ControlEvent(ControlEvent::CET_TEXT);
|
||||||
|
if (!controlEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
controlEvent->setTextEventData(text);
|
||||||
|
m_inputConvert.sendControlEvent(controlEvent);
|
||||||
|
}
|
||||||
|
|
||||||
void VideoForm::postGoHome()
|
void VideoForm::postGoHome()
|
||||||
{
|
{
|
||||||
postKeyCodeClick(AKEYCODE_HOME);
|
postKeyCodeClick(AKEYCODE_HOME);
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
void postVolumeDown();
|
void postVolumeDown();
|
||||||
// turn the screen on if it was off, press BACK otherwise
|
// turn the screen on if it was off, press BACK otherwise
|
||||||
void postTurnOn();
|
void postTurnOn();
|
||||||
|
void postTextInput(const QString& text);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateShowSize(const QSize &newSize);
|
void updateShowSize(const QSize &newSize);
|
||||||
|
|
3
TODO.txt
3
TODO.txt
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
中英文翻译
|
|
||||||
tool tips
|
|
||||||
server移除
|
server移除
|
||||||
mp4录制
|
mp4录制
|
||||||
工具栏扩展(模拟点击指定次数等)
|
工具栏扩展(模拟点击指定次数等)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue