You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef CONTROLEVENT_H
#define CONTROLEVENT_H
#include <QRect>
#include <QString>
#include <QBuffer>
#include "qscrcpyevent.h"
#include "input.h"
#include "keycodes.h"
#define CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON 0
#define TEXT_MAX_CHARACTER_LENGTH 300
// ControlEvent
class ControlEvent : public QScrcpyEvent
{
public:
enum ControlEventType {
CET_KEYCODE,
CET_TEXT,
CET_MOUSE,
CET_SCROLL,
CET_COMMAND,
CET_TOUCH,
};
ControlEvent(ControlEventType controlEventType);
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_DOWNAMOTION_EVENT_ACTION_UPAMOTION_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);
QByteArray serializeData();
private:
void write32(QBuffer& buffer, quint32 value);
void write16(QBuffer& buffer, quint32 value);
void writePosition(QBuffer& buffer, const QRect& value);
private:
struct ControlEventData {
ControlEventType type;
union {
struct {
AndroidKeyeventAction action;
AndroidKeycode keycode;
AndroidMetastate metastate;
} keycodeEvent;
struct {
char text[TEXT_MAX_CHARACTER_LENGTH + 1];
} textEvent;
struct {
AndroidMotioneventAction action;
AndroidMotioneventButtons buttons;
QRect position;
} mouseEvent;
struct {
quint32 id;
AndroidMotioneventAction action;
QRect position;
} touchEvent;
struct {
QRect position;
qint32 hScroll;
qint32 vScroll;
} scrollEvent;
struct {
qint32 action;
} commandEvent;
};
ControlEventData(){}
~ControlEventData(){}
};
ControlEventData m_data;
};
#endif // CONTROLEVENT_H