Event.cs 1.8 KB

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