Event.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Space = 32,
  47. Delete = 127,
  48. AltMask = 0x80000000,
  49. Backspace = 0x100000,
  50. CursorUp,
  51. CursorDown,
  52. CursorLeft,
  53. CursorRight,
  54. PageUp,
  55. PageDown,
  56. Home,
  57. End,
  58. DeleteChar,
  59. InsertChar,
  60. F1,
  61. F2,
  62. F3,
  63. F4,
  64. F5,
  65. F6,
  66. F7,
  67. F8,
  68. F9,
  69. F10,
  70. BackTab,
  71. Unknown
  72. }
  73. public struct KeyEvent {
  74. public Key Key;
  75. public int KeyValue => (int)KeyValue;
  76. public bool IsAlt => (Key & Key.AltMask) != 0;
  77. public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26);
  78. public KeyEvent (Key k)
  79. {
  80. Key = k;
  81. }
  82. }
  83. public class Event {
  84. public class Key : Event {
  85. public int Code { get; private set; }
  86. public bool Alt { get; private set; }
  87. public Key (int code)
  88. {
  89. Code = code;
  90. }
  91. }
  92. public class Mouse : Event {
  93. }
  94. public static Event CreateMouseEvent ()
  95. {
  96. return new Mouse ();
  97. }
  98. public static Event CreateKeyEvent (int code)
  99. {
  100. return new Key (code);
  101. }
  102. }
  103. }