controlmsg.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef CONTROLMSG_H
  2. #define CONTROLMSG_H
  3. #include "inputconvertbase.h"
  4. #include <stdint.h>
  5. #include "input.h"
  6. #include "keycodes.h"
  7. #include <string>
  8. #define CONTROL_MSG_TEXT_MAX_LENGTH 300
  9. #define CONTROL_MSG_CLIPBOARD_TEXT_MAX_LENGTH 4093
  10. // ControlMsg
  11. class ControlMsg
  12. {
  13. public:
  14. enum ControlMsgType {
  15. CMT_NULL = -1,
  16. CMT_INJECT_KEYCODE = 0,
  17. CMT_INJECT_TEXT,
  18. CMT_INJECT_MOUSE,
  19. CMT_INJECT_SCROLL,
  20. CMT_BACK_OR_SCREEN_ON,
  21. CMT_EXPAND_NOTIFICATION_PANEL,
  22. CMT_COLLAPSE_NOTIFICATION_PANEL,
  23. CMT_GET_CLIPBOARD,
  24. CMT_SET_CLIPBOARD,
  25. CMT_SET_SCREEN_POWER_MODE,
  26. CMT_INJECT_TOUCH,
  27. CMT_SET_MIRROR,
  28. };
  29. ControlMsg(ControlMsgType controlMsgType);
  30. virtual ~ControlMsg();
  31. void setInjectKeycodeMsgData(AndroidKeyeventAction action, AndroidKeycode keycode, AndroidMetastate metastate);
  32. void setInjectTextMsgData(std::string text);
  33. void setInjectMouseMsgData(AndroidMotioneventAction action, AndroidMotioneventButtons buttons, Rect position);
  34. // id 代表一个触摸点,最多支持10个触摸点[0,9]
  35. // action 只能是AMOTION_EVENT_ACTION_DOWN,AMOTION_EVENT_ACTION_UP,AMOTION_EVENT_ACTION_MOVE
  36. // position action动作对应的位置
  37. void setInjectTouchMsgData(unsigned int id, AndroidMotioneventAction action, Rect position);
  38. void setInjectScrollMsgData(Rect position, unsigned int hScroll, unsigned int vScroll);
  39. void setSetClipboardMsgData(std::string text);
  40. void setSetScreenPowerModeData(ScreenPowerMode mode);
  41. void setMirrorModeData(MirrorMode mode);
  42. uint8_t* serializeData();
  43. void writePosition(uint8_t* buffer, const Rect& value);
  44. void WriteButton(uint8_t* buffer, unsigned int value);
  45. private:
  46. private:
  47. struct ControlMsgData {
  48. ControlMsgType type = CMT_NULL;
  49. //union {
  50. struct {
  51. AndroidKeyeventAction action;
  52. AndroidKeycode keycode;
  53. AndroidMetastate metastate;
  54. } injectKeycode;
  55. struct {
  56. char* text;
  57. } injectText;
  58. struct {
  59. AndroidMotioneventAction action;
  60. AndroidMotioneventButtons buttons;
  61. Rect position;
  62. } injectMouse;
  63. struct {
  64. unsigned int id;
  65. AndroidMotioneventAction action;
  66. Rect position;
  67. } injectTouch;
  68. struct {
  69. Rect position;
  70. unsigned int hScroll;
  71. unsigned int vScroll;
  72. } injectScroll;
  73. struct {
  74. char *text ;
  75. } setClipboard;
  76. struct {
  77. ScreenPowerMode mode;
  78. } setScreenPowerMode;
  79. struct{
  80. MirrorMode mode;
  81. } setMirrorMode;
  82. //};
  83. ControlMsgData(){}
  84. ~ControlMsgData(){}
  85. };
  86. ControlMsgData m_data;
  87. };
  88. #endif // CONTROLMSG_H