fix:输入文本的bug

This commit is contained in:
Barry 2019-01-26 19:43:30 +08:00
parent 4109c4724d
commit b29c4fae6e
6 changed files with 25 additions and 16 deletions

View file

@ -41,7 +41,7 @@
<property name="title">
<string>Wireless</string>
</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">
<widget class="QLabel" name="label">
<property name="minimumSize">

View file

@ -2,8 +2,6 @@
#include "controlevent.h"
#define TEXT_MAX_CHARACTER_LENGTH 300
ControlEvent::ControlEvent(ControlEventType controlEventType)
: QScrcpyEvent(Control)
{
@ -19,7 +17,14 @@ void ControlEvent::setKeycodeEventData(AndroidKeyeventAction action, AndroidKeyc
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)
@ -85,14 +90,8 @@ QByteArray ControlEvent::serializeData()
break;
case CET_TEXT:
{
// write length (2 byte) + date (non nul-terminated)
if (TEXT_MAX_CHARACTER_LENGTH < m_data.textEvent.text.length()) {
// 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());
write16(buffer, strlen(m_data.textEvent.text));
buffer.write(m_data.textEvent.text, strlen(m_data.textEvent.text));
}
break;
case CET_MOUSE:

View file

@ -10,6 +10,8 @@
#include "keycodes.h"
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
#define TEXT_MAX_CHARACTER_LENGTH 300
// ControlEvent
class ControlEvent : public QScrcpyEvent
{
@ -52,7 +54,7 @@ private:
AndroidMetastate metastate;
} keycodeEvent;
struct {
QString text;
char text[TEXT_MAX_CHARACTER_LENGTH + 1];
} textEvent;
struct {
AndroidMotioneventAction action;

View file

@ -259,6 +259,16 @@ void VideoForm::postTurnOn()
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()
{
postKeyCodeClick(AKEYCODE_HOME);

View file

@ -33,6 +33,7 @@ public:
void postVolumeDown();
// turn the screen on if it was off, press BACK otherwise
void postTurnOn();
void postTextInput(const QString& text);
private:
void updateShowSize(const QSize &newSize);

View file

@ -1,6 +1,3 @@
中英文翻译
tool tips
server移除
mp4录制
工具栏扩展(模拟点击指定次数等)