Event.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Evemts.cs: Events, Key mappings
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. namespace Terminal {
  8. /// <summary>
  9. /// The Key enumeration contains special encoding for some keys, but can also
  10. /// encode all the unicode values that can be passed.
  11. /// </summary>
  12. /// <remarks>
  13. /// <para>
  14. /// If the SpecialMask is set, then the value is that of the special mask,
  15. /// otherwise, the value is the one of the lower bits (as extracted by CharMask)
  16. /// </para>
  17. /// <para>
  18. /// Control keys are the values between 1 and 26 corresponding to Control-A to Control-Z
  19. /// </para>
  20. /// </remarks>
  21. public enum Key : uint {
  22. CharMask = 0xfffff,
  23. SpecialMask = 0xfff00000,
  24. ControlA = 1,
  25. ControlB,
  26. ControlC,
  27. ControlD,
  28. ControlE,
  29. ControlF,
  30. ControlG,
  31. ControlH,
  32. ControlI,
  33. Tab = ControlI,
  34. ControlJ,
  35. ControlK,
  36. ControlL,
  37. ControlM,
  38. ControlN,
  39. ControlO,
  40. ControlP,
  41. ControlQ,
  42. ControlR,
  43. ControlS,
  44. ControlT,
  45. ControlU,
  46. ControlV,
  47. ControlW,
  48. ControlX,
  49. ControlY,
  50. ControlZ,
  51. Esc = 27,
  52. Enter = '\n',
  53. Space = 32,
  54. Delete = 127,
  55. AltMask = 0x80000000,
  56. Backspace = 0x100000,
  57. CursorUp,
  58. CursorDown,
  59. CursorLeft,
  60. CursorRight,
  61. PageUp,
  62. PageDown,
  63. Home,
  64. End,
  65. DeleteChar,
  66. InsertChar,
  67. F1,
  68. F2,
  69. F3,
  70. F4,
  71. F5,
  72. F6,
  73. F7,
  74. F8,
  75. F9,
  76. F10,
  77. BackTab,
  78. Unknown
  79. }
  80. public struct KeyEvent {
  81. public Key Key;
  82. public int KeyValue => (int)Key;
  83. public bool IsAlt => (Key & Key.AltMask) != 0;
  84. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26);
  85. public KeyEvent (Key k)
  86. {
  87. Key = k;
  88. }
  89. }
  90. public class Event {
  91. public class Key : Event {
  92. public int Code { get; private set; }
  93. public bool Alt { get; private set; }
  94. public Key (int code)
  95. {
  96. Code = code;
  97. }
  98. }
  99. public class Mouse : Event {
  100. }
  101. public static Event CreateMouseEvent ()
  102. {
  103. return new Mouse ();
  104. }
  105. public static Event CreateKeyEvent (int code)
  106. {
  107. return new Key (code);
  108. }
  109. }
  110. }