mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +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">
|
||||
<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">
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
3
TODO.txt
3
TODO.txt
|
@ -1,6 +1,3 @@
|
|||
|
||||
中英文翻译
|
||||
tool tips
|
||||
server移除
|
||||
mp4录制
|
||||
工具栏扩展(模拟点击指定次数等)
|
||||
|
|
Loading…
Add table
Reference in a new issue