2
0

Event.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. //
  2. // Evemts.cs: Events, Key mappings
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. using System;
  8. namespace Terminal.Gui {
  9. /// <summary>
  10. /// Identifies the state of the "shift"-keys within a event.
  11. /// </summary>
  12. public class KeyModifiers {
  13. /// <summary>
  14. /// Check if the Shift key was pressed or not.
  15. /// </summary>
  16. public bool Shift;
  17. /// <summary>
  18. /// Check if the Alt key was pressed or not.
  19. /// </summary>
  20. public bool Alt;
  21. /// <summary>
  22. /// Check if the Ctrl key was pressed or not.
  23. /// </summary>
  24. public bool Ctrl;
  25. /// <summary>
  26. /// Check if the Caps lock key was pressed or not.
  27. /// </summary>
  28. public bool Capslock;
  29. /// <summary>
  30. /// Check if the Num lock key was pressed or not.
  31. /// </summary>
  32. public bool Numlock;
  33. /// <summary>
  34. /// Check if the Scroll lock key was pressed or not.
  35. /// </summary>
  36. public bool Scrolllock;
  37. }
  38. /// <summary>
  39. /// The <see cref="Key"/> enumeration contains special encoding for some keys, but can also
  40. /// encode all the unicode values that can be passed.
  41. /// </summary>
  42. /// <remarks>
  43. /// <para>
  44. /// If the <see cref="SpecialMask"/> is set, then the value is that of the special mask,
  45. /// otherwise, the value is the one of the lower bits (as extracted by <see cref="CharMask"/>)
  46. /// <para>
  47. /// Numerics keys are the values between 48 and 57 corresponding to 0 to 9
  48. /// </para>
  49. /// </para>
  50. /// <para>
  51. /// Upper alpha keys are the values between 65 and 90 corresponding to A to Z
  52. /// </para>
  53. /// <para>
  54. /// Unicode runes are also stored here, the letter 'A" for example is encoded as a value 65 (not surfaced in the enum).
  55. /// </para>
  56. /// </remarks>
  57. [Flags]
  58. public enum Key : uint {
  59. /// <summary>
  60. /// Mask that indicates that this is a character value, values outside this range
  61. /// indicate special characters like Alt-key combinations or special keys on the
  62. /// keyboard like function keys, arrows keys and so on.
  63. /// </summary>
  64. CharMask = 0xfffff,
  65. /// <summary>
  66. /// If the <see cref="SpecialMask"/> is set, then the value is that of the special mask,
  67. /// otherwise, the value is the one of the lower bits (as extracted by <see cref="CharMask"/>).
  68. /// </summary>
  69. SpecialMask = 0xfff00000,
  70. /// <summary>
  71. /// The key code representing null or empty
  72. /// </summary>
  73. Null = '\0',
  74. /// <summary>
  75. /// Backspace key.
  76. /// </summary>
  77. Backspace = 8,
  78. /// <summary>
  79. /// The key code for the user pressing the tab key (forwards tab key).
  80. /// </summary>
  81. Tab = 9,
  82. /// <summary>
  83. /// The key code for the user pressing the return key.
  84. /// </summary>
  85. Enter = '\n',
  86. /// <summary>
  87. /// The key code for the user pressing the clear key.
  88. /// </summary>
  89. Clear = 12,
  90. /// <summary>
  91. /// The key code for the user pressing the escape key
  92. /// </summary>
  93. Esc = 27,
  94. /// <summary>
  95. /// The key code for the user pressing the space bar
  96. /// </summary>
  97. Space = 32,
  98. /// <summary>
  99. /// Digit 0.
  100. /// </summary>
  101. D0 = 48,
  102. /// <summary>
  103. /// Digit 1.
  104. /// </summary>
  105. D1,
  106. /// <summary>
  107. /// Digit 2.
  108. /// </summary>
  109. D2,
  110. /// <summary>
  111. /// Digit 3.
  112. /// </summary>
  113. D3,
  114. /// <summary>
  115. /// Digit 4.
  116. /// </summary>
  117. D4,
  118. /// <summary>
  119. /// Digit 5.
  120. /// </summary>
  121. D5,
  122. /// <summary>
  123. /// Digit 6.
  124. /// </summary>
  125. D6,
  126. /// <summary>
  127. /// Digit 7.
  128. /// </summary>
  129. D7,
  130. /// <summary>
  131. /// Digit 8.
  132. /// </summary>
  133. D8,
  134. /// <summary>
  135. /// Digit 9.
  136. /// </summary>
  137. D9,
  138. /// <summary>
  139. /// The key code for the user pressing Shift-A
  140. /// </summary>
  141. A = 65,
  142. /// <summary>
  143. /// The key code for the user pressing Shift-B
  144. /// </summary>
  145. B,
  146. /// <summary>
  147. /// The key code for the user pressing Shift-C
  148. /// </summary>
  149. C,
  150. /// <summary>
  151. /// The key code for the user pressing Shift-D
  152. /// </summary>
  153. D,
  154. /// <summary>
  155. /// The key code for the user pressing Shift-E
  156. /// </summary>
  157. E,
  158. /// <summary>
  159. /// The key code for the user pressing Shift-F
  160. /// </summary>
  161. F,
  162. /// <summary>
  163. /// The key code for the user pressing Shift-G
  164. /// </summary>
  165. G,
  166. /// <summary>
  167. /// The key code for the user pressing Shift-H
  168. /// </summary>
  169. H,
  170. /// <summary>
  171. /// The key code for the user pressing Shift-I
  172. /// </summary>
  173. I,
  174. /// <summary>
  175. /// The key code for the user pressing Shift-J
  176. /// </summary>
  177. J,
  178. /// <summary>
  179. /// The key code for the user pressing Shift-K
  180. /// </summary>
  181. K,
  182. /// <summary>
  183. /// The key code for the user pressing Shift-L
  184. /// </summary>
  185. L,
  186. /// <summary>
  187. /// The key code for the user pressing Shift-M
  188. /// </summary>
  189. M,
  190. /// <summary>
  191. /// The key code for the user pressing Shift-N
  192. /// </summary>
  193. N,
  194. /// <summary>
  195. /// The key code for the user pressing Shift-O
  196. /// </summary>
  197. O,
  198. /// <summary>
  199. /// The key code for the user pressing Shift-P
  200. /// </summary>
  201. P,
  202. /// <summary>
  203. /// The key code for the user pressing Shift-Q
  204. /// </summary>
  205. Q,
  206. /// <summary>
  207. /// The key code for the user pressing Shift-R
  208. /// </summary>
  209. R,
  210. /// <summary>
  211. /// The key code for the user pressing Shift-S
  212. /// </summary>
  213. S,
  214. /// <summary>
  215. /// The key code for the user pressing Shift-T
  216. /// </summary>
  217. T,
  218. /// <summary>
  219. /// The key code for the user pressing Shift-U
  220. /// </summary>
  221. U,
  222. /// <summary>
  223. /// The key code for the user pressing Shift-V
  224. /// </summary>
  225. V,
  226. /// <summary>
  227. /// The key code for the user pressing Shift-W
  228. /// </summary>
  229. W,
  230. /// <summary>
  231. /// The key code for the user pressing Shift-X
  232. /// </summary>
  233. X,
  234. /// <summary>
  235. /// The key code for the user pressing Shift-Y
  236. /// </summary>
  237. Y,
  238. /// <summary>
  239. /// The key code for the user pressing Shift-Z
  240. /// </summary>
  241. Z,
  242. /// <summary>
  243. /// The key code for the user pressing A
  244. /// </summary>
  245. a = 97,
  246. /// <summary>
  247. /// The key code for the user pressing B
  248. /// </summary>
  249. b,
  250. /// <summary>
  251. /// The key code for the user pressing C
  252. /// </summary>
  253. c,
  254. /// <summary>
  255. /// The key code for the user pressing D
  256. /// </summary>
  257. d,
  258. /// <summary>
  259. /// The key code for the user pressing E
  260. /// </summary>
  261. e,
  262. /// <summary>
  263. /// The key code for the user pressing F
  264. /// </summary>
  265. f,
  266. /// <summary>
  267. /// The key code for the user pressing G
  268. /// </summary>
  269. g,
  270. /// <summary>
  271. /// The key code for the user pressing H
  272. /// </summary>
  273. h,
  274. /// <summary>
  275. /// The key code for the user pressing I
  276. /// </summary>
  277. i,
  278. /// <summary>
  279. /// The key code for the user pressing J
  280. /// </summary>
  281. j,
  282. /// <summary>
  283. /// The key code for the user pressing K
  284. /// </summary>
  285. k,
  286. /// <summary>
  287. /// The key code for the user pressing L
  288. /// </summary>
  289. l,
  290. /// <summary>
  291. /// The key code for the user pressing M
  292. /// </summary>
  293. m,
  294. /// <summary>
  295. /// The key code for the user pressing N
  296. /// </summary>
  297. n,
  298. /// <summary>
  299. /// The key code for the user pressing O
  300. /// </summary>
  301. o,
  302. /// <summary>
  303. /// The key code for the user pressing P
  304. /// </summary>
  305. p,
  306. /// <summary>
  307. /// The key code for the user pressing Q
  308. /// </summary>
  309. q,
  310. /// <summary>
  311. /// The key code for the user pressing R
  312. /// </summary>
  313. r,
  314. /// <summary>
  315. /// The key code for the user pressing S
  316. /// </summary>
  317. s,
  318. /// <summary>
  319. /// The key code for the user pressing T
  320. /// </summary>
  321. t,
  322. /// <summary>
  323. /// The key code for the user pressing U
  324. /// </summary>
  325. u,
  326. /// <summary>
  327. /// The key code for the user pressing V
  328. /// </summary>
  329. v,
  330. /// <summary>
  331. /// The key code for the user pressing W
  332. /// </summary>
  333. w,
  334. /// <summary>
  335. /// The key code for the user pressing X
  336. /// </summary>
  337. x,
  338. /// <summary>
  339. /// The key code for the user pressing Y
  340. /// </summary>
  341. y,
  342. /// <summary>
  343. /// The key code for the user pressing Z
  344. /// </summary>
  345. z,
  346. /// <summary>
  347. /// The key code for the user pressing the delete key.
  348. /// </summary>
  349. Delete = 127,
  350. /// <summary>
  351. /// When this value is set, the Key encodes the sequence Shift-KeyValue.
  352. /// </summary>
  353. ShiftMask = 0x10000000,
  354. /// <summary>
  355. /// When this value is set, the Key encodes the sequence Alt-KeyValue.
  356. /// And the actual value must be extracted by removing the AltMask.
  357. /// </summary>
  358. AltMask = 0x80000000,
  359. /// <summary>
  360. /// When this value is set, the Key encodes the sequence Ctrl-KeyValue.
  361. /// And the actual value must be extracted by removing the CtrlMask.
  362. /// </summary>
  363. CtrlMask = 0x40000000,
  364. /// <summary>
  365. /// Cursor up key
  366. /// </summary>
  367. CursorUp = 0x100000,
  368. /// <summary>
  369. /// Cursor down key.
  370. /// </summary>
  371. CursorDown,
  372. /// <summary>
  373. /// Cursor left key.
  374. /// </summary>
  375. CursorLeft,
  376. /// <summary>
  377. /// Cursor right key.
  378. /// </summary>
  379. CursorRight,
  380. /// <summary>
  381. /// Page Up key.
  382. /// </summary>
  383. PageUp,
  384. /// <summary>
  385. /// Page Down key.
  386. /// </summary>
  387. PageDown,
  388. /// <summary>
  389. /// Home key.
  390. /// </summary>
  391. Home,
  392. /// <summary>
  393. /// End key.
  394. /// </summary>
  395. End,
  396. /// <summary>
  397. /// Insert character key.
  398. /// </summary>
  399. InsertChar,
  400. /// <summary>
  401. /// Delete character key.
  402. /// </summary>
  403. DeleteChar,
  404. /// <summary>
  405. /// Shift-tab key (backwards tab key).
  406. /// </summary>
  407. BackTab,
  408. /// <summary>
  409. /// Print screen character key.
  410. /// </summary>
  411. PrintScreen,
  412. /// <summary>
  413. /// F1 key.
  414. /// </summary>
  415. F1,
  416. /// <summary>
  417. /// F2 key.
  418. /// </summary>
  419. F2,
  420. /// <summary>
  421. /// F3 key.
  422. /// </summary>
  423. F3,
  424. /// <summary>
  425. /// F4 key.
  426. /// </summary>
  427. F4,
  428. /// <summary>
  429. /// F5 key.
  430. /// </summary>
  431. F5,
  432. /// <summary>
  433. /// F6 key.
  434. /// </summary>
  435. F6,
  436. /// <summary>
  437. /// F7 key.
  438. /// </summary>
  439. F7,
  440. /// <summary>
  441. /// F8 key.
  442. /// </summary>
  443. F8,
  444. /// <summary>
  445. /// F9 key.
  446. /// </summary>
  447. F9,
  448. /// <summary>
  449. /// F10 key.
  450. /// </summary>
  451. F10,
  452. /// <summary>
  453. /// F11 key.
  454. /// </summary>
  455. F11,
  456. /// <summary>
  457. /// F12 key.
  458. /// </summary>
  459. F12,
  460. /// <summary>
  461. /// F13 key.
  462. /// </summary>
  463. F13,
  464. /// <summary>
  465. /// F14 key.
  466. /// </summary>
  467. F14,
  468. /// <summary>
  469. /// F15 key.
  470. /// </summary>
  471. F15,
  472. /// <summary>
  473. /// F16 key.
  474. /// </summary>
  475. F16,
  476. /// <summary>
  477. /// F17 key.
  478. /// </summary>
  479. F17,
  480. /// <summary>
  481. /// F18 key.
  482. /// </summary>
  483. F18,
  484. /// <summary>
  485. /// F19 key.
  486. /// </summary>
  487. F19,
  488. /// <summary>
  489. /// F20 key.
  490. /// </summary>
  491. F20,
  492. /// <summary>
  493. /// F21 key.
  494. /// </summary>
  495. F21,
  496. /// <summary>
  497. /// F22 key.
  498. /// </summary>
  499. F22,
  500. /// <summary>
  501. /// F23 key.
  502. /// </summary>
  503. F23,
  504. /// <summary>
  505. /// F24 key.
  506. /// </summary>
  507. F24,
  508. /// <summary>
  509. /// A key with an unknown mapping was raised.
  510. /// </summary>
  511. Unknown
  512. }
  513. /// <summary>
  514. /// Describes a keyboard event.
  515. /// </summary>
  516. public class KeyEvent {
  517. KeyModifiers keyModifiers;
  518. /// <summary>
  519. /// Symbolic definition for the key.
  520. /// </summary>
  521. public Key Key;
  522. /// <summary>
  523. /// The key value cast to an integer, you will typical use this for
  524. /// extracting the Unicode rune value out of a key, when none of the
  525. /// symbolic options are in use.
  526. /// </summary>
  527. public int KeyValue => (int)Key;
  528. /// <summary>
  529. /// Gets a value indicating whether the Shift key was pressed.
  530. /// </summary>
  531. /// <value><c>true</c> if is shift; otherwise, <c>false</c>.</value>
  532. public bool IsShift => keyModifiers.Shift || Key == Key.BackTab;
  533. /// <summary>
  534. /// Gets a value indicating whether the Alt key was pressed (real or synthesized)
  535. /// </summary>
  536. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  537. public bool IsAlt => keyModifiers.Alt;
  538. /// <summary>
  539. /// Determines whether the value is a control key (and NOT just the ctrl key)
  540. /// </summary>
  541. /// <value><c>true</c> if is ctrl; otherwise, <c>false</c>.</value>
  542. //public bool IsCtrl => ((uint)Key >= 1) && ((uint)Key <= 26);
  543. public bool IsCtrl => keyModifiers.Ctrl;
  544. /// <summary>
  545. /// Gets a value indicating whether the Caps lock key was pressed (real or synthesized)
  546. /// </summary>
  547. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  548. public bool IsCapslock => keyModifiers.Capslock;
  549. /// <summary>
  550. /// Gets a value indicating whether the Num lock key was pressed (real or synthesized)
  551. /// </summary>
  552. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  553. public bool IsNumlock => keyModifiers.Numlock;
  554. /// <summary>
  555. /// Gets a value indicating whether the Scroll lock key was pressed (real or synthesized)
  556. /// </summary>
  557. /// <value><c>true</c> if is alternate; otherwise, <c>false</c>.</value>
  558. public bool IsScrolllock => keyModifiers.Scrolllock;
  559. /// <summary>
  560. /// Constructs a new <see cref="KeyEvent"/>
  561. /// </summary>
  562. public KeyEvent ()
  563. {
  564. Key = Key.Unknown;
  565. keyModifiers = new KeyModifiers ();
  566. }
  567. /// <summary>
  568. /// Constructs a new <see cref="KeyEvent"/> from the provided Key value - can be a rune cast into a Key value
  569. /// </summary>
  570. public KeyEvent (Key k, KeyModifiers km)
  571. {
  572. Key = k;
  573. keyModifiers = km;
  574. }
  575. /// <summary>
  576. /// Pretty prints the KeyEvent
  577. /// </summary>
  578. /// <returns></returns>
  579. public override string ToString ()
  580. {
  581. string msg = "";
  582. var key = this.Key;
  583. if (keyModifiers.Shift) {
  584. msg += "Shift-";
  585. }
  586. if (keyModifiers.Alt) {
  587. msg += "Alt-";
  588. }
  589. if (keyModifiers.Ctrl) {
  590. msg += "Ctrl-";
  591. }
  592. if (keyModifiers.Capslock) {
  593. msg += "Capslock-";
  594. }
  595. if (keyModifiers.Numlock) {
  596. msg += "Numlock-";
  597. }
  598. if (keyModifiers.Scrolllock) {
  599. msg += "Scrolllock-";
  600. }
  601. msg += $"{((Key)KeyValue != Key.Unknown && ((uint)this.KeyValue & (uint)Key.CharMask) > 27 ? $"{(char)this.KeyValue}" : $"{key}")}";
  602. return msg;
  603. }
  604. }
  605. /// <summary>
  606. /// Mouse flags reported in <see cref="MouseEvent"/>.
  607. /// </summary>
  608. /// <remarks>
  609. /// They just happen to map to the ncurses ones.
  610. /// </remarks>
  611. [Flags]
  612. public enum MouseFlags {
  613. /// <summary>
  614. /// The first mouse button was pressed.
  615. /// </summary>
  616. Button1Pressed = unchecked((int)0x2),
  617. /// <summary>
  618. /// The first mouse button was released.
  619. /// </summary>
  620. Button1Released = unchecked((int)0x1),
  621. /// <summary>
  622. /// The first mouse button was clicked (press+release).
  623. /// </summary>
  624. Button1Clicked = unchecked((int)0x4),
  625. /// <summary>
  626. /// The first mouse button was double-clicked.
  627. /// </summary>
  628. Button1DoubleClicked = unchecked((int)0x8),
  629. /// <summary>
  630. /// The first mouse button was triple-clicked.
  631. /// </summary>
  632. Button1TripleClicked = unchecked((int)0x10),
  633. /// <summary>
  634. /// The second mouse button was pressed.
  635. /// </summary>
  636. Button2Pressed = unchecked((int)0x80),
  637. /// <summary>
  638. /// The second mouse button was released.
  639. /// </summary>
  640. Button2Released = unchecked((int)0x40),
  641. /// <summary>
  642. /// The second mouse button was clicked (press+release).
  643. /// </summary>
  644. Button2Clicked = unchecked((int)0x100),
  645. /// <summary>
  646. /// The second mouse button was double-clicked.
  647. /// </summary>
  648. Button2DoubleClicked = unchecked((int)0x200),
  649. /// <summary>
  650. /// The second mouse button was triple-clicked.
  651. /// </summary>
  652. Button2TripleClicked = unchecked((int)0x400),
  653. /// <summary>
  654. /// The third mouse button was pressed.
  655. /// </summary>
  656. Button3Pressed = unchecked((int)0x2000),
  657. /// <summary>
  658. /// The third mouse button was released.
  659. /// </summary>
  660. Button3Released = unchecked((int)0x1000),
  661. /// <summary>
  662. /// The third mouse button was clicked (press+release).
  663. /// </summary>
  664. Button3Clicked = unchecked((int)0x4000),
  665. /// <summary>
  666. /// The third mouse button was double-clicked.
  667. /// </summary>
  668. Button3DoubleClicked = unchecked((int)0x8000),
  669. /// <summary>
  670. /// The third mouse button was triple-clicked.
  671. /// </summary>
  672. Button3TripleClicked = unchecked((int)0x10000),
  673. /// <summary>
  674. /// The fourth mouse button was pressed.
  675. /// </summary>
  676. Button4Pressed = unchecked((int)0x80000),
  677. /// <summary>
  678. /// The fourth mouse button was released.
  679. /// </summary>
  680. Button4Released = unchecked((int)0x40000),
  681. /// <summary>
  682. /// The fourth button was clicked (press+release).
  683. /// </summary>
  684. Button4Clicked = unchecked((int)0x100000),
  685. /// <summary>
  686. /// The fourth button was double-clicked.
  687. /// </summary>
  688. Button4DoubleClicked = unchecked((int)0x200000),
  689. /// <summary>
  690. /// The fourth button was triple-clicked.
  691. /// </summary>
  692. Button4TripleClicked = unchecked((int)0x400000),
  693. /// <summary>
  694. /// Flag: the shift key was pressed when the mouse button took place.
  695. /// </summary>
  696. ButtonShift = unchecked((int)0x2000000),
  697. /// <summary>
  698. /// Flag: the ctrl key was pressed when the mouse button took place.
  699. /// </summary>
  700. ButtonCtrl = unchecked((int)0x1000000),
  701. /// <summary>
  702. /// Flag: the alt key was pressed when the mouse button took place.
  703. /// </summary>
  704. ButtonAlt = unchecked((int)0x4000000),
  705. /// <summary>
  706. /// The mouse position is being reported in this event.
  707. /// </summary>
  708. ReportMousePosition = unchecked((int)0x8000000),
  709. /// <summary>
  710. /// Vertical button wheeled up.
  711. /// </summary>
  712. WheeledUp = unchecked((int)0x10000000),
  713. /// <summary>
  714. /// Vertical button wheeled down.
  715. /// </summary>
  716. WheeledDown = unchecked((int)0x20000000),
  717. /// <summary>
  718. /// Vertical button wheeled up while pressing ButtonShift.
  719. /// </summary>
  720. WheeledLeft = ButtonShift | WheeledUp,
  721. /// <summary>
  722. /// Vertical button wheeled down while pressing ButtonShift.
  723. /// </summary>
  724. WheeledRight = ButtonShift | WheeledDown,
  725. /// <summary>
  726. /// Mask that captures all the events.
  727. /// </summary>
  728. AllEvents = unchecked((int)0x7ffffff),
  729. }
  730. /// <summary>
  731. /// Low-level construct that conveys the details of mouse events, such
  732. /// as coordinates and button state, from ConsoleDrivers up to <see cref="Application"/> and
  733. /// Views.
  734. /// </summary>
  735. /// <remarks>The <see cref="Application"/> class includes the <see cref="Application.RootMouseEvent"/>
  736. /// Action which takes a MouseEvent argument.</remarks>
  737. public class MouseEvent {
  738. /// <summary>
  739. /// The X (column) location for the mouse event.
  740. /// </summary>
  741. public int X { get; set; }
  742. /// <summary>
  743. /// The Y (column) location for the mouse event.
  744. /// </summary>
  745. public int Y { get; set; }
  746. /// <summary>
  747. /// Flags indicating the kind of mouse event that is being posted.
  748. /// </summary>
  749. public MouseFlags Flags { get; set; }
  750. /// <summary>
  751. /// The offset X (column) location for the mouse event.
  752. /// </summary>
  753. public int OfX { get; set; }
  754. /// <summary>
  755. /// The offset Y (column) location for the mouse event.
  756. /// </summary>
  757. public int OfY { get; set; }
  758. /// <summary>
  759. /// The current view at the location for the mouse event.
  760. /// </summary>
  761. public View View { get; set; }
  762. /// <summary>
  763. /// Indicates if the current mouse event has already been processed and the driver should stop notifying any other event subscriber.
  764. /// Its important to set this value to true specially when updating any View's layout from inside the subscriber method.
  765. /// </summary>
  766. public bool Handled { get; set; }
  767. /// <summary>
  768. /// Returns a <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.
  769. /// </summary>
  770. /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="MouseEvent"/>.</returns>
  771. public override string ToString ()
  772. {
  773. return $"({X},{Y}:{Flags}";
  774. }
  775. }
  776. }