KeyboardTests.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. using Xunit.Abstractions;
  2. namespace Terminal.Gui.ApplicationTests;
  3. /// <summary>
  4. /// Application tests for keyboard support.
  5. /// </summary>
  6. public class KeyboardTests
  7. {
  8. public KeyboardTests (ITestOutputHelper output)
  9. {
  10. _output = output;
  11. #if DEBUG_IDISPOSABLE
  12. View.Instances.Clear ();
  13. RunState.Instances.Clear ();
  14. #endif
  15. }
  16. private readonly ITestOutputHelper _output;
  17. private object _timeoutLock;
  18. [Fact (Skip = "No longer valid test.")]
  19. [AutoInitShutdown]
  20. public void EnsuresTopOnFront_CanFocus_False_By_Keyboard ()
  21. {
  22. Toplevel top = new ();
  23. var win = new Window
  24. {
  25. Title = "win",
  26. X = 0,
  27. Y = 0,
  28. Width = 20,
  29. Height = 10
  30. };
  31. var tf = new TextField { Width = 10 };
  32. win.Add (tf);
  33. var win2 = new Window
  34. {
  35. Title = "win2",
  36. X = 22,
  37. Y = 0,
  38. Width = 20,
  39. Height = 10
  40. };
  41. var tf2 = new TextField { Width = 10 };
  42. win2.Add (tf2);
  43. top.Add (win, win2);
  44. Application.Begin (top);
  45. Assert.True (win.CanFocus);
  46. Assert.True (win.HasFocus);
  47. Assert.True (win2.CanFocus);
  48. Assert.False (win2.HasFocus);
  49. Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
  50. win.CanFocus = false;
  51. Assert.False (win.CanFocus);
  52. Assert.False (win.HasFocus);
  53. Assert.True (win2.CanFocus);
  54. Assert.True (win2.HasFocus);
  55. Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
  56. Application.RaiseKeyDownEvent (Key.F6);
  57. Assert.True (win2.CanFocus);
  58. Assert.False (win.HasFocus);
  59. Assert.True (win2.CanFocus);
  60. Assert.True (win2.HasFocus);
  61. Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
  62. Application.RaiseKeyDownEvent (Key.F6);
  63. Assert.False (win.CanFocus);
  64. Assert.False (win.HasFocus);
  65. Assert.True (win2.CanFocus);
  66. Assert.True (win2.HasFocus);
  67. Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
  68. top.Dispose ();
  69. }
  70. [Fact (Skip = "No longer valid test.")]
  71. [AutoInitShutdown]
  72. public void EnsuresTopOnFront_CanFocus_True_By_Keyboard ()
  73. {
  74. Toplevel top = new ();
  75. var win = new Window
  76. {
  77. Title = "win",
  78. X = 0,
  79. Y = 0,
  80. Width = 20,
  81. Height = 10
  82. };
  83. var tf = new TextField { Width = 10 };
  84. win.Add (tf);
  85. var win2 = new Window
  86. {
  87. Title = "win2",
  88. X = 22,
  89. Y = 0,
  90. Width = 20,
  91. Height = 10
  92. };
  93. var tf2 = new TextField { Width = 10 };
  94. win2.Add (tf2);
  95. top.Add (win, win2);
  96. Application.Begin (top);
  97. Assert.True (win.CanFocus);
  98. Assert.True (win.HasFocus);
  99. Assert.True (win2.CanFocus);
  100. Assert.False (win2.HasFocus);
  101. Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
  102. Application.RaiseKeyDownEvent (Key.F6);
  103. Assert.True (win.CanFocus);
  104. Assert.False (win.HasFocus);
  105. Assert.True (win2.CanFocus);
  106. Assert.True (win2.HasFocus);
  107. Assert.Equal ("win2", ((Window)top.Subviews [^1]).Title);
  108. Application.RaiseKeyDownEvent (Key.F6);
  109. Assert.True (win.CanFocus);
  110. Assert.True (win.HasFocus);
  111. Assert.True (win2.CanFocus);
  112. Assert.False (win2.HasFocus);
  113. Assert.Equal ("win", ((Window)top.Subviews [^1]).Title);
  114. top.Dispose ();
  115. }
  116. [Fact]
  117. [AutoInitShutdown]
  118. public void KeyBinding_Application_KeyBindings_Add_Adds ()
  119. {
  120. Application.KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Accept);
  121. Application.KeyBindings.Add (Key.B, KeyBindingScope.Application, Command.Accept);
  122. Assert.True (Application.KeyBindings.TryGet (Key.A, out KeyBinding binding));
  123. Assert.Null (binding.BoundView);
  124. Assert.True (Application.KeyBindings.TryGet (Key.B, out binding));
  125. Assert.Null (binding.BoundView);
  126. }
  127. [Fact]
  128. [AutoInitShutdown]
  129. public void KeyBinding_Application_RemoveKeyBinding_Removes ()
  130. {
  131. Application.KeyBindings.Add (Key.A, KeyBindingScope.Application, Command.Accept);
  132. Assert.True (Application.KeyBindings.TryGet (Key.A, out _));
  133. Application.KeyBindings.Remove (Key.A);
  134. Assert.False (Application.KeyBindings.TryGet (Key.A, out _));
  135. }
  136. [Fact]
  137. public void KeyBinding_OnKeyDown ()
  138. {
  139. Application.Top = new Toplevel ();
  140. var view = new ScopedKeyBindingView ();
  141. var keyWasHandled = false;
  142. view.KeyDownNotHandled += (s, e) => keyWasHandled = true;
  143. Application.Top.Add (view);
  144. Application.RaiseKeyDownEvent (Key.A);
  145. Assert.False (keyWasHandled);
  146. Assert.True (view.ApplicationCommand);
  147. keyWasHandled = false;
  148. view.ApplicationCommand = false;
  149. Application.KeyBindings.Remove (KeyCode.A);
  150. Application.RaiseKeyDownEvent (Key.A); // old
  151. Assert.False (keyWasHandled);
  152. Assert.False (view.ApplicationCommand);
  153. Application.KeyBindings.Add (Key.A.WithCtrl, view, Command.Save);
  154. Application.RaiseKeyDownEvent (Key.A); // old
  155. Assert.False (keyWasHandled);
  156. Assert.False (view.ApplicationCommand);
  157. Application.RaiseKeyDownEvent (Key.A.WithCtrl); // new
  158. Assert.False (keyWasHandled);
  159. Assert.True (view.ApplicationCommand);
  160. keyWasHandled = false;
  161. Application.RaiseKeyDownEvent (Key.H);
  162. Assert.False (keyWasHandled);
  163. keyWasHandled = false;
  164. Assert.False (view.HasFocus);
  165. Application.RaiseKeyDownEvent (Key.F);
  166. Assert.False (keyWasHandled);
  167. Assert.True (view.ApplicationCommand);
  168. Assert.True (view.HotKeyCommand);
  169. Assert.False (view.FocusedCommand);
  170. Application.Top.Dispose ();
  171. Application.ResetState (true);
  172. }
  173. [Fact]
  174. [AutoInitShutdown]
  175. public void KeyBinding_OnKeyDown_Negative ()
  176. {
  177. var view = new ScopedKeyBindingView ();
  178. var keyWasHandled = false;
  179. view.KeyDownNotHandled += (s, e) => keyWasHandled = true;
  180. var top = new Toplevel ();
  181. top.Add (view);
  182. Application.Begin (top);
  183. Application.RaiseKeyDownEvent (Key.A.WithCtrl);
  184. Assert.False (keyWasHandled);
  185. Assert.False (view.ApplicationCommand);
  186. Assert.False (view.HotKeyCommand);
  187. Assert.False (view.FocusedCommand);
  188. keyWasHandled = false;
  189. Assert.False (view.HasFocus);
  190. Application.RaiseKeyDownEvent (Key.Z);
  191. Assert.False (keyWasHandled);
  192. Assert.False (view.ApplicationCommand);
  193. Assert.False (view.HotKeyCommand);
  194. Assert.False (view.FocusedCommand);
  195. top.Dispose ();
  196. }
  197. [Fact]
  198. [AutoInitShutdown]
  199. public void KeyBinding_View_KeyBindings_Add_Adds ()
  200. {
  201. View view1 = new ();
  202. Application.KeyBindings.Add (Key.A, view1, Command.Accept);
  203. View view2 = new ();
  204. Application.KeyBindings.Add (Key.B, view2, Command.Accept);
  205. Assert.True (Application.KeyBindings.TryGet (Key.A, out KeyBinding binding));
  206. Assert.Equal (view1, binding.BoundView);
  207. Assert.True (Application.KeyBindings.TryGet (Key.B, out binding));
  208. Assert.Equal (view2, binding.BoundView);
  209. }
  210. [Fact]
  211. [AutoInitShutdown]
  212. public void KeyBinding_View_KeyBindings_RemoveKeyBinding_Removes ()
  213. {
  214. View view1 = new ();
  215. Application.KeyBindings.Add (Key.A, view1, Command.Accept);
  216. View view2 = new ();
  217. Application.KeyBindings.Add (Key.B, view1, Command.Accept);
  218. Application.KeyBindings.Remove (Key.A, view1);
  219. Assert.False (Application.KeyBindings.TryGet (Key.A, out _));
  220. }
  221. [Fact]
  222. public void KeyUp_Event ()
  223. {
  224. Application.Init (new FakeDriver ());
  225. // Setup some fake keypresses (This)
  226. var input = "Tests";
  227. Key originalQuitKey = Application.QuitKey;
  228. Application.QuitKey = Key.Q.WithCtrl;
  229. // Put a control-q in at the end
  230. FakeConsole.MockKeyPresses.Push (new ('Q', ConsoleKey.Q, false, false, true));
  231. foreach (char c in input.Reverse ())
  232. {
  233. if (char.IsLetter (c))
  234. {
  235. FakeConsole.MockKeyPresses.Push (
  236. new (
  237. c,
  238. (ConsoleKey)char.ToUpper (c),
  239. char.IsUpper (c),
  240. false,
  241. false
  242. )
  243. );
  244. }
  245. else
  246. {
  247. FakeConsole.MockKeyPresses.Push (
  248. new (
  249. c,
  250. (ConsoleKey)c,
  251. false,
  252. false,
  253. false
  254. )
  255. );
  256. }
  257. }
  258. int stackSize = FakeConsole.MockKeyPresses.Count;
  259. var iterations = 0;
  260. Application.Iteration += (s, a) =>
  261. {
  262. iterations++;
  263. // Stop if we run out of control...
  264. if (iterations > 10)
  265. {
  266. Application.RequestStop ();
  267. }
  268. };
  269. var keyUps = 0;
  270. var output = string.Empty;
  271. var top = new Toplevel ();
  272. top.KeyUp += (sender, args) =>
  273. {
  274. if (args.KeyCode != (KeyCode.CtrlMask | KeyCode.Q))
  275. {
  276. output += args.AsRune;
  277. }
  278. keyUps++;
  279. };
  280. Application.Run (top);
  281. Application.QuitKey = originalQuitKey;
  282. // Input string should match output
  283. Assert.Equal (input, output);
  284. // # of key up events should match stack size
  285. //Assert.Equal (stackSize, keyUps);
  286. // We can't use numbers variables on the left side of an Assert.Equal/NotEqual,
  287. // it must be literal (Linux only).
  288. Assert.Equal (6, keyUps);
  289. // # of key up events should match # of iterations
  290. Assert.Equal (stackSize, iterations);
  291. top.Dispose ();
  292. Application.Shutdown ();
  293. Assert.Null (Application.Top);
  294. Assert.Null (Application.MainLoop);
  295. Assert.Null (Application.Driver);
  296. }
  297. [Fact]
  298. public void NextTabGroupKey_Moves_Focus_To_TabStop_In_Next_TabGroup ()
  299. {
  300. // Arrange
  301. Application.Navigation = new ();
  302. var top = new Toplevel ();
  303. var view1 = new View
  304. {
  305. Id = "view1",
  306. CanFocus = true,
  307. TabStop = TabBehavior.TabGroup
  308. };
  309. var subView1 = new View
  310. {
  311. Id = "subView1",
  312. CanFocus = true,
  313. TabStop = TabBehavior.TabStop
  314. };
  315. view1.Add (subView1);
  316. var view2 = new View
  317. {
  318. Id = "view2",
  319. CanFocus = true,
  320. TabStop = TabBehavior.TabGroup
  321. };
  322. var subView2 = new View
  323. {
  324. Id = "subView2",
  325. CanFocus = true,
  326. TabStop = TabBehavior.TabStop
  327. };
  328. view2.Add (subView2);
  329. top.Add (view1, view2);
  330. Application.Top = top;
  331. view1.SetFocus ();
  332. Assert.True (view1.HasFocus);
  333. Assert.True (subView1.HasFocus);
  334. // Act
  335. Application.RaiseKeyDownEvent (Application.NextTabGroupKey);
  336. // Assert
  337. Assert.True (view2.HasFocus);
  338. Assert.True (subView2.HasFocus);
  339. top.Dispose ();
  340. Application.Navigation = null;
  341. }
  342. [Fact]
  343. public void NextTabGroupKey_PrevTabGroupKey_Tests ()
  344. {
  345. Application.Init (new FakeDriver ());
  346. Toplevel top = new (); // TabGroup
  347. var w1 = new Window (); // TabGroup
  348. var v1 = new TextField (); // TabStop
  349. var v2 = new TextView (); // TabStop
  350. w1.Add (v1, v2);
  351. var w2 = new Window (); // TabGroup
  352. var v3 = new CheckBox (); // TabStop
  353. var v4 = new Button (); // TabStop
  354. w2.Add (v3, v4);
  355. top.Add (w1, w2);
  356. Application.Iteration += (s, a) =>
  357. {
  358. Assert.True (v1.HasFocus);
  359. // Across TabGroups
  360. Application.RaiseKeyDownEvent (Key.F6);
  361. Assert.True (v3.HasFocus);
  362. Application.RaiseKeyDownEvent (Key.F6);
  363. Assert.True (v1.HasFocus);
  364. Application.RaiseKeyDownEvent (Key.F6.WithShift);
  365. Assert.True (v3.HasFocus);
  366. Application.RaiseKeyDownEvent (Key.F6.WithShift);
  367. Assert.True (v1.HasFocus);
  368. // Restore?
  369. Application.RaiseKeyDownEvent (Key.Tab);
  370. Assert.True (v2.HasFocus);
  371. Application.RaiseKeyDownEvent (Key.F6);
  372. Assert.True (v3.HasFocus);
  373. Application.RaiseKeyDownEvent (Key.F6);
  374. Assert.True (v1.HasFocus);
  375. Application.RequestStop ();
  376. };
  377. Application.Run (top);
  378. // Replacing the defaults keys to avoid errors on others unit tests that are using it.
  379. Application.NextTabGroupKey = Key.PageDown.WithCtrl;
  380. Application.PrevTabGroupKey = Key.PageUp.WithCtrl;
  381. Application.QuitKey = Key.Q.WithCtrl;
  382. Assert.Equal (KeyCode.PageDown | KeyCode.CtrlMask, Application.NextTabGroupKey.KeyCode);
  383. Assert.Equal (KeyCode.PageUp | KeyCode.CtrlMask, Application.PrevTabGroupKey.KeyCode);
  384. Assert.Equal (KeyCode.Q | KeyCode.CtrlMask, Application.QuitKey.KeyCode);
  385. top.Dispose ();
  386. // Shutdown must be called to safely clean up Application if Init has been called
  387. Application.Shutdown ();
  388. }
  389. [Fact]
  390. public void NextTabKey_Moves_Focus_To_Next_TabStop ()
  391. {
  392. // Arrange
  393. Application.Navigation = new ();
  394. var top = new Toplevel ();
  395. var view1 = new View { Id = "view1", CanFocus = true };
  396. var view2 = new View { Id = "view2", CanFocus = true };
  397. top.Add (view1, view2);
  398. Application.Top = top;
  399. view1.SetFocus ();
  400. // Act
  401. Application.RaiseKeyDownEvent (Application.NextTabKey);
  402. // Assert
  403. Assert.True (view2.HasFocus);
  404. top.Dispose ();
  405. Application.Navigation = null;
  406. }
  407. [Fact]
  408. public void PrevTabGroupKey_Moves_Focus_To_TabStop_In_Prev_TabGroup ()
  409. {
  410. // Arrange
  411. Application.Navigation = new ();
  412. var top = new Toplevel ();
  413. var view1 = new View
  414. {
  415. Id = "view1",
  416. CanFocus = true,
  417. TabStop = TabBehavior.TabGroup
  418. };
  419. var subView1 = new View
  420. {
  421. Id = "subView1",
  422. CanFocus = true,
  423. TabStop = TabBehavior.TabStop
  424. };
  425. view1.Add (subView1);
  426. var view2 = new View
  427. {
  428. Id = "view2",
  429. CanFocus = true,
  430. TabStop = TabBehavior.TabGroup
  431. };
  432. var subView2 = new View
  433. {
  434. Id = "subView2",
  435. CanFocus = true,
  436. TabStop = TabBehavior.TabStop
  437. };
  438. view2.Add (subView2);
  439. top.Add (view1, view2);
  440. Application.Top = top;
  441. view1.SetFocus ();
  442. Assert.True (view1.HasFocus);
  443. Assert.True (subView1.HasFocus);
  444. // Act
  445. Application.RaiseKeyDownEvent (Application.PrevTabGroupKey);
  446. // Assert
  447. Assert.True (view2.HasFocus);
  448. Assert.True (subView2.HasFocus);
  449. top.Dispose ();
  450. Application.Navigation = null;
  451. }
  452. [Fact]
  453. public void PrevTabKey_Moves_Focus_To_Prev_TabStop ()
  454. {
  455. // Arrange
  456. Application.Navigation = new ();
  457. var top = new Toplevel ();
  458. var view1 = new View { Id = "view1", CanFocus = true };
  459. var view2 = new View { Id = "view2", CanFocus = true };
  460. top.Add (view1, view2);
  461. Application.Top = top;
  462. view1.SetFocus ();
  463. // Act
  464. Application.RaiseKeyDownEvent (Application.NextTabKey);
  465. // Assert
  466. Assert.True (view2.HasFocus);
  467. top.Dispose ();
  468. Application.Navigation = null;
  469. }
  470. [Fact]
  471. public void QuitKey_Default_Is_Esc ()
  472. {
  473. Application.ResetState (true);
  474. // Before Init
  475. Assert.Equal (Key.Esc, Application.QuitKey);
  476. Application.Init (new FakeDriver ());
  477. // After Init
  478. Assert.Equal (Key.Esc, Application.QuitKey);
  479. Application.Shutdown ();
  480. }
  481. [Fact]
  482. [AutoInitShutdown]
  483. public void QuitKey_Getter_Setter ()
  484. {
  485. Toplevel top = new ();
  486. var isQuiting = false;
  487. top.Closing += (s, e) =>
  488. {
  489. isQuiting = true;
  490. e.Cancel = true;
  491. };
  492. Application.Begin (top);
  493. top.Running = true;
  494. Key prevKey = Application.QuitKey;
  495. Application.RaiseKeyDownEvent (Application.QuitKey);
  496. Assert.True (isQuiting);
  497. isQuiting = false;
  498. Application.RaiseKeyDownEvent (Application.QuitKey);
  499. Assert.True (isQuiting);
  500. isQuiting = false;
  501. Application.QuitKey = Key.C.WithCtrl;
  502. Application.RaiseKeyDownEvent (prevKey); // Should not quit
  503. Assert.False (isQuiting);
  504. Application.RaiseKeyDownEvent (Key.Q.WithCtrl); // Should not quit
  505. Assert.False (isQuiting);
  506. Application.RaiseKeyDownEvent (Application.QuitKey);
  507. Assert.True (isQuiting);
  508. // Reset the QuitKey to avoid throws errors on another tests
  509. Application.QuitKey = prevKey;
  510. top.Dispose ();
  511. }
  512. [Fact]
  513. public void QuitKey_Quits ()
  514. {
  515. Assert.Null (_timeoutLock);
  516. _timeoutLock = new ();
  517. uint abortTime = 500;
  518. var initialized = false;
  519. var iteration = 0;
  520. var shutdown = false;
  521. object timeout = null;
  522. Application.InitializedChanged += OnApplicationOnInitializedChanged;
  523. Application.Init (new FakeDriver ());
  524. Assert.True (initialized);
  525. Assert.False (shutdown);
  526. _output.WriteLine ("Application.Run<Toplevel> ().Dispose ()..");
  527. Application.Run<Toplevel> ().Dispose ();
  528. _output.WriteLine ("Back from Application.Run<Toplevel> ().Dispose ()");
  529. Assert.True (initialized);
  530. Assert.False (shutdown);
  531. Assert.Equal (1, iteration);
  532. Application.Shutdown ();
  533. Application.InitializedChanged -= OnApplicationOnInitializedChanged;
  534. lock (_timeoutLock)
  535. {
  536. if (timeout is { })
  537. {
  538. Application.RemoveTimeout (timeout);
  539. timeout = null;
  540. }
  541. }
  542. Assert.True (initialized);
  543. Assert.True (shutdown);
  544. #if DEBUG_IDISPOSABLE
  545. Assert.Empty (View.Instances);
  546. #endif
  547. lock (_timeoutLock)
  548. {
  549. _timeoutLock = null;
  550. }
  551. return;
  552. void OnApplicationOnInitializedChanged (object s, EventArgs<bool> a)
  553. {
  554. _output.WriteLine ("OnApplicationOnInitializedChanged: {0}", a.CurrentValue);
  555. if (a.CurrentValue)
  556. {
  557. Application.Iteration += OnApplicationOnIteration;
  558. initialized = true;
  559. lock (_timeoutLock)
  560. {
  561. timeout = Application.AddTimeout (TimeSpan.FromMilliseconds (abortTime), ForceCloseCallback);
  562. }
  563. }
  564. else
  565. {
  566. Application.Iteration -= OnApplicationOnIteration;
  567. shutdown = true;
  568. }
  569. }
  570. bool ForceCloseCallback ()
  571. {
  572. lock (_timeoutLock)
  573. {
  574. _output.WriteLine ($"ForceCloseCallback. iteration: {iteration}");
  575. if (timeout is { })
  576. {
  577. timeout = null;
  578. }
  579. }
  580. Application.ResetState (true);
  581. Assert.Fail ($"Failed to Quit with {Application.QuitKey} after {abortTime}ms. Force quit.");
  582. return false;
  583. }
  584. void OnApplicationOnIteration (object s, IterationEventArgs a)
  585. {
  586. _output.WriteLine ("Iteration: {0}", iteration);
  587. iteration++;
  588. Assert.True (iteration < 2, "Too many iterations, something is wrong.");
  589. if (Application.Initialized)
  590. {
  591. _output.WriteLine (" Pressing QuitKey");
  592. Application.RaiseKeyDownEvent (Application.QuitKey);
  593. }
  594. }
  595. }
  596. // Test View for testing Application key Bindings
  597. public class ScopedKeyBindingView : View
  598. {
  599. public ScopedKeyBindingView ()
  600. {
  601. AddCommand (Command.Save, () => ApplicationCommand = true);
  602. AddCommand (Command.HotKey, () => HotKeyCommand = true);
  603. AddCommand (Command.Left, () => FocusedCommand = true);
  604. Application.KeyBindings.Add (Key.A, this, Command.Save);
  605. HotKey = KeyCode.H;
  606. KeyBindings.Add (Key.F, Command.Left);
  607. }
  608. public bool ApplicationCommand { get; set; }
  609. public bool FocusedCommand { get; set; }
  610. public bool HotKeyCommand { get; set; }
  611. }
  612. }