2
0

Event.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // Evemts.cs: Events, Key mappings
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. using System;
  8. namespace Terminal {
  9. /// <summary>
  10. /// The Key enumeration contains special encoding for some keys, but can also
  11. /// encode all the unicode values that can be passed.
  12. /// </summary>
  13. /// <remarks>
  14. /// <para>
  15. /// If the SpecialMask is set, then the value is that of the special mask,
  16. /// otherwise, the value is the one of the lower bits (as extracted by CharMask)
  17. /// </para>
  18. /// <para>
  19. /// Control keys are the values between 1 and 26 corresponding to Control-A to Control-Z
  20. /// </para>
  21. /// </remarks>
  22. public enum Key : uint {
  23. CharMask = 0xfffff,
  24. /// <summary>
  25. /// If the SpecialMask is set, then the value is that of the special mask,
  26. /// otherwise, the value is the one of the lower bits (as extracted by CharMask).
  27. /// </summary>
  28. SpecialMask = 0xfff00000,
  29. ControlA = 1,
  30. ControlB,
  31. ControlC,
  32. ControlD,
  33. ControlE,
  34. ControlF,
  35. ControlG,
  36. ControlH,
  37. ControlI,
  38. Tab = ControlI,
  39. ControlJ,
  40. ControlK,
  41. ControlL,
  42. ControlM,
  43. ControlN,
  44. ControlO,
  45. ControlP,
  46. ControlQ,
  47. ControlR,
  48. ControlS,
  49. ControlT,
  50. ControlU,
  51. ControlV,
  52. ControlW,
  53. ControlX,
  54. ControlY,
  55. ControlZ,
  56. Esc = 27,
  57. Enter = '\n',
  58. Space = 32,
  59. Delete = 127,
  60. AltMask = 0x80000000,
  61. Backspace = 0x100000,
  62. CursorUp,
  63. CursorDown,
  64. CursorLeft,
  65. CursorRight,
  66. PageUp,
  67. PageDown,
  68. Home,
  69. End,
  70. DeleteChar,
  71. InsertChar,
  72. F1,
  73. F2,
  74. F3,
  75. F4,
  76. F5,
  77. F6,
  78. F7,
  79. F8,
  80. F9,
  81. F10,
  82. BackTab,
  83. Unknown
  84. }
  85. /// <summary>
  86. /// Describes a keyboard event
  87. /// </summary>
  88. public struct KeyEvent {
  89. public Key Key;
  90. public int KeyValue => (int)Key;
  91. /// <summary>
  92. /// Gets a value indicating whether the Alt key was pressed (real or synthesized)
  93. /// </summary>
  94. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  95. public bool IsAlt => (Key & Key.AltMask) != 0;
  96. /// <summary>
  97. /// Determines whether the value is a control key
  98. /// </summary>
  99. /// <value><c>true</c> if is ctrl; otherwise, <c>false</c>.</value>
  100. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26);
  101. public KeyEvent (Key k)
  102. {
  103. Key = k;
  104. }
  105. }
  106. /// <summary>
  107. /// Mouse flags reported in MouseEvent.
  108. /// </summary>
  109. /// <remarks>
  110. /// They just happen to map to the ncurses ones.
  111. /// </remarks>
  112. [Flags]
  113. public enum MouseFlags {
  114. Button1Pressed = unchecked((int)0x2),
  115. Button1Released = unchecked((int)0x1),
  116. Button1Clicked = unchecked((int)0x4),
  117. Button1DoubleClicked = unchecked((int)0x8),
  118. Button1TripleClicked = unchecked((int)0x10),
  119. Button2Pressed = unchecked((int)0x80),
  120. Button2Released = unchecked((int)0x40),
  121. Button2Clicked = unchecked((int)0x100),
  122. Button2DoubleClicked = unchecked((int)0x200),
  123. Button2TrippleClicked = unchecked((int)0x400),
  124. Button3Pressed = unchecked((int)0x2000),
  125. Button3Released = unchecked((int)0x1000),
  126. Button3Clicked = unchecked((int)0x4000),
  127. Button3DoubleClicked = unchecked((int)0x8000),
  128. Button3TripleClicked = unchecked((int)0x10000),
  129. Button4Pressed = unchecked((int)0x80000),
  130. Button4Released = unchecked((int)0x40000),
  131. Button4Clicked = unchecked((int)0x100000),
  132. Button4DoubleClicked = unchecked((int)0x200000),
  133. Button4TripleClicked = unchecked((int)0x400000),
  134. ButtonShift = unchecked((int)0x2000000),
  135. ButtonCtrl = unchecked((int)0x1000000),
  136. ButtonAlt = unchecked((int)0x4000000),
  137. ReportMousePosition = unchecked((int)0x8000000),
  138. AllEvents = unchecked((int)0x7ffffff),
  139. }
  140. /// <summary>
  141. /// Describes a mouse event
  142. /// </summary>
  143. public struct MouseEvent {
  144. /// <summary>
  145. /// The X (column) location for the mouse event.
  146. /// </summary>
  147. public int X;
  148. /// <summary>
  149. /// The Y (column) location for the mouse event.
  150. /// </summary>
  151. public int Y;
  152. /// <summary>
  153. /// Flags indicating the kind of mouse event that is being posted.
  154. /// </summary>
  155. public MouseFlags Flags;
  156. /// <summary>
  157. /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:Terminal.MouseEvent"/>.
  158. /// </summary>
  159. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:Terminal.MouseEvent"/>.</returns>
  160. public override string ToString()
  161. {
  162. return $"({X},{Y}:{Flags}";
  163. }
  164. }
  165. }