MouseEvent.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*----------------------------------------------------------------
  2. // Copyright (C) 2007 liu523@QQ.COM
  3. // 版权所有。
  4. // 开发者:liu523@QQ.COM团队
  5. // 文件名:MoseEvent.cs
  6. // 文件功能描述:涉及到屏幕管理的指令-鼠标控制指令。
  7. //----------------------------------------------------------------*/
  8. using System;
  9. namespace RemoteControlLib.Codes
  10. {
  11. /// <summary>
  12. /// 鼠标事件类型
  13. /// </summary>
  14. [Serializable]
  15. public enum MouseEventType
  16. {
  17. MouseMove,
  18. MouseLeftDown,
  19. MouseLeftUp,
  20. MouseRightDown,
  21. MouseRightUp,
  22. MouseClick,
  23. MouseDoubleClick
  24. }
  25. /// <summary>
  26. /// 鼠标事件结构
  27. /// </summary>
  28. [Serializable]
  29. public class MouseEvent : BaseCode
  30. {
  31. private Byte[] type;
  32. private Byte[] x;
  33. private Byte[] y;
  34. /// <summary>
  35. /// 创建鼠标事件的实例
  36. /// </summary>
  37. /// <param name="Type">类型</param>
  38. /// <param name="X">鼠标指针的X坐标</param>
  39. /// <param name="Y">鼠标指针的Y坐标</param>
  40. public MouseEvent(MouseEventType Type, int X, int Y)
  41. {
  42. this.type = BitConverter.GetBytes((int)Type);
  43. this.x = BitConverter.GetBytes(X);
  44. this.y = BitConverter.GetBytes(Y);
  45. }
  46. public MouseEvent(Byte[] Type, Byte[] X, Byte[] Y)
  47. {
  48. this.type = Type;
  49. this.x = X;
  50. this.y = Y;
  51. }
  52. public MouseEvent(Byte[] Content)
  53. {
  54. type = new byte[4];
  55. x = new byte[4];
  56. y = new byte[4];
  57. for (int i = 0; i < Content.Length; i++)
  58. {
  59. if (i >= 0 && i < 4)
  60. type[i] = Content[i];
  61. if (i >= 4 && i < 8)
  62. x[i - 4] = Content[i];
  63. if (i >= 8 && i < 12)
  64. y[i - 8] = Content[i];
  65. }
  66. }
  67. /// <summary>
  68. /// 类型
  69. /// </summary>
  70. public MouseEventType Type
  71. {
  72. get { return (MouseEventType)BitConverter.ToInt32(type, 0); }
  73. }
  74. /// <summary>
  75. /// 鼠标指针的X坐标
  76. /// </summary>
  77. public int X
  78. {
  79. get { return BitConverter.ToInt32(x, 0); }
  80. }
  81. /// <summary>
  82. /// 鼠标指针的Y坐标
  83. /// </summary>
  84. public int Y
  85. {
  86. get { return BitConverter.ToInt32(y, 0); }
  87. }
  88. public Byte[] ToBytes()
  89. {
  90. Byte[] Bytes = new Byte[12];
  91. type.CopyTo(Bytes, 0);
  92. x.CopyTo(Bytes, 4);
  93. y.CopyTo(Bytes, 8);
  94. return Bytes;
  95. }
  96. }
  97. }