Event.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. SpecialMask = 0xfff00000,
  25. ControlA = 1,
  26. ControlB,
  27. ControlC,
  28. ControlD,
  29. ControlE,
  30. ControlF,
  31. ControlG,
  32. ControlH,
  33. ControlI,
  34. Tab = ControlI,
  35. ControlJ,
  36. ControlK,
  37. ControlL,
  38. ControlM,
  39. ControlN,
  40. ControlO,
  41. ControlP,
  42. ControlQ,
  43. ControlR,
  44. ControlS,
  45. ControlT,
  46. ControlU,
  47. ControlV,
  48. ControlW,
  49. ControlX,
  50. ControlY,
  51. ControlZ,
  52. Esc = 27,
  53. Enter = '\n',
  54. Space = 32,
  55. Delete = 127,
  56. AltMask = 0x80000000,
  57. Backspace = 0x100000,
  58. CursorUp,
  59. CursorDown,
  60. CursorLeft,
  61. CursorRight,
  62. PageUp,
  63. PageDown,
  64. Home,
  65. End,
  66. DeleteChar,
  67. InsertChar,
  68. F1,
  69. F2,
  70. F3,
  71. F4,
  72. F5,
  73. F6,
  74. F7,
  75. F8,
  76. F9,
  77. F10,
  78. BackTab,
  79. Unknown
  80. }
  81. /// <summary>
  82. /// Describes a keyboard event
  83. /// </summary>
  84. public struct KeyEvent {
  85. public Key Key;
  86. public int KeyValue => (int)Key;
  87. /// <summary>
  88. /// Gets a value indicating whether the Alt key was pressed (real or synthesized)
  89. /// </summary>
  90. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  91. public bool IsAlt => (Key & Key.AltMask) != 0;
  92. /// <summary>
  93. /// Determines whether the value is a control key
  94. /// </summary>
  95. /// <value><c>true</c> if is ctrl; otherwise, <c>false</c>.</value>
  96. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26);
  97. public KeyEvent (Key k)
  98. {
  99. Key = k;
  100. }
  101. }
  102. /// <summary>
  103. /// Mouse flags reported in MouseEvent.
  104. /// </summary>
  105. /// <remarks>
  106. /// They just happen to map to the ncurses ones.
  107. /// </remarks>
  108. [Flags]
  109. public enum MouseFlags {
  110. Button1Pressed = unchecked((int)0x2),
  111. Button1Released = unchecked((int)0x1),
  112. Button1Clicked = unchecked((int)0x4),
  113. Button1DoubleClicked = unchecked((int)0x8),
  114. Button1TripleClicked = unchecked((int)0x10),
  115. Button2Pressed = unchecked((int)0x80),
  116. Button2Released = unchecked((int)0x40),
  117. Button2Clicked = unchecked((int)0x100),
  118. Button2DoubleClicked = unchecked((int)0x200),
  119. Button2TrippleClicked = unchecked((int)0x400),
  120. Button3Pressed = unchecked((int)0x2000),
  121. Button3Released = unchecked((int)0x1000),
  122. Button3Clicked = unchecked((int)0x4000),
  123. Button3DoubleClicked = unchecked((int)0x8000),
  124. Button3TripleClicked = unchecked((int)0x10000),
  125. Button4Pressed = unchecked((int)0x80000),
  126. Button4Released = unchecked((int)0x40000),
  127. Button4Clicked = unchecked((int)0x100000),
  128. Button4DoubleClicked = unchecked((int)0x200000),
  129. Button4TripleClicked = unchecked((int)0x400000),
  130. ButtonShift = unchecked((int)0x2000000),
  131. ButtonCtrl = unchecked((int)0x1000000),
  132. ButtonAlt = unchecked((int)0x4000000),
  133. ReportMousePosition = unchecked((int)0x8000000),
  134. AllEvents = unchecked((int)0x7ffffff),
  135. }
  136. /// <summary>
  137. /// Describes a mouse event
  138. /// </summary>
  139. public struct MouseEvent {
  140. /// <summary>
  141. /// The X (column) location for the mouse event.
  142. /// </summary>
  143. public int X;
  144. /// <summary>
  145. /// The Y (column) location for the mouse event.
  146. /// </summary>
  147. public int Y;
  148. /// <summary>
  149. /// Flags indicating the kind of mouse event that is being posted.
  150. /// </summary>
  151. public MouseFlags Flags;
  152. }
  153. }