keyboard.html 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!DOCTYPE html>
  2. <!--[if IE]><![endif]-->
  3. <html>
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <title>Keyboard Event Processing </title>
  8. <meta name="viewport" content="width=device-width">
  9. <meta name="title" content="Keyboard Event Processing ">
  10. <meta name="generator" content="docfx 2.59.3.0">
  11. <link rel="shortcut icon" href="../favicon.ico">
  12. <link rel="stylesheet" href="../styles/docfx.vendor.css">
  13. <link rel="stylesheet" href="../styles/docfx.css">
  14. <link rel="stylesheet" href="../styles/main.css">
  15. <meta property="docfx:navrel" content="../toc.html">
  16. <meta property="docfx:tocrel" content="../toc.html">
  17. <meta property="docfx:rel" content="../">
  18. </head>
  19. <body data-spy="scroll" data-target="#affix" data-offset="120">
  20. <div id="wrapper">
  21. <header>
  22. <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
  23. <div class="container">
  24. <div class="navbar-header">
  25. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
  26. <span class="sr-only">Toggle navigation</span>
  27. <span class="icon-bar"></span>
  28. <span class="icon-bar"></span>
  29. <span class="icon-bar"></span>
  30. </button>
  31. <a class="navbar-brand" href="../index.html">
  32. <img id="logo" class="svg" src="../images/logo48.png" alt="">
  33. </a>
  34. </div>
  35. <div class="collapse navbar-collapse" id="navbar">
  36. <form class="navbar-form navbar-right" role="search" id="search">
  37. <div class="form-group">
  38. <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
  39. </div>
  40. </form>
  41. </div>
  42. </div>
  43. </nav>
  44. <div class="subnav navbar navbar-default">
  45. <div class="container hide-when-search" id="breadcrumb">
  46. <ul class="breadcrumb">
  47. <li></li>
  48. </ul>
  49. </div>
  50. </div>
  51. </header>
  52. <div class="container body-content">
  53. <div id="search-results">
  54. <div class="search-list">Search Results for <span></span></div>
  55. <div class="sr-items">
  56. <p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
  57. </div>
  58. <ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul>
  59. </div>
  60. </div>
  61. <div role="main" class="container body-content hide-when-search">
  62. <div class="article row grid">
  63. <div class="col-md-10">
  64. <article class="content wrap" id="_content" data-uid="">
  65. <h1 id="keyboard-event-processing">Keyboard Event Processing</h1>
  66. <p>Keyboard events are sent by the <a href="mainloop.html">Main Loop</a> to the
  67. Application class for processing. The keyboard events are sent
  68. exclusively to the current <code>Toplevel</code>, this being either the default
  69. that is created when you call <code>Application.Init</code>, or one that you
  70. created an passed to <code>Application.Run(Toplevel)</code>. </p>
  71. <h2 id="flow">Flow</h2>
  72. <p>Keystrokes are first processes as hotkeys, then as regular keys, and
  73. there is a final cold post-processing event that is invoked if no view
  74. processed the key.</p>
  75. <h2 id="hotkey-processing">HotKey Processing</h2>
  76. <p>Events are first send to all views as a &quot;HotKey&quot;, this means that the
  77. <code>View.ProcessHotKey</code> method is invoked on the current toplevel, which
  78. in turns propagates this to all the views in the hierarchy. If any
  79. view decides to process the event, no further processing takes place.</p>
  80. <p>This is how hotkeys for buttons are implemented. For example, the
  81. keystroke &quot;Alt-A&quot; is handled by Buttons that have a hot-letter &quot;A&quot; to
  82. activate the button.</p>
  83. <h2 id="regular-processing">Regular Processing</h2>
  84. <p>Unlike the hotkey processing, the regular processing is only sent to
  85. the currently focused view in the focus chain.</p>
  86. <p>The regular key processing is only invoked if no hotkey was caught.</p>
  87. <h2 id="cold-key-processing">Cold-key Processing</h2>
  88. <p>This stage only is executed if the focused view did not process the
  89. event, and is broadcast to all the views in the Toplevel.</p>
  90. <p>This method can be overwritten by views that want to provide
  91. accelerator functionality (Alt-key for example), but without
  92. interfering with normal ProcessKey behavior.</p>
  93. <h2 id="key-bindings">Key Bindings</h2>
  94. <p><strong>Terminal.Gui</strong> supports rebinding keys. For example the default key
  95. for activating a button is Enter. You can change this using the
  96. <code>ClearKeybinding</code> and <code>AddKeybinding</code> methods:</p>
  97. <pre><code class="lang-csharp">var btn = new Button (&quot;Press Me&quot;);
  98. btn.ClearKeybinding (Command.Accept);
  99. btn.AddKeyBinding (Key.b, Command.Accept);
  100. </code></pre><p>The <code>Command</code> enum lists generic operations that are implemented by views.
  101. For example <code>Command.Accept</code> in a Button results in the <code>Clicked</code> event
  102. firing while in <code>TableView</code> it is bound to <code>CellActivated</code>. Not all commands
  103. are implemented by all views (e.g. you cannot scroll in a Button). To see
  104. which commands are implemented by a View you can use the <code>GetSupportedCommands()</code>
  105. method.</p>
  106. <p>Not all controls have the same key bound for a given command, for example
  107. <code>Command.Accept</code> defaults to <code>Key.Enter</code> in a <code>Button</code> but defaults to <code>Key.Space</code>
  108. in <code>RadioGroup</code>.</p>
  109. <h2 id="global-key-handler">Global Key Handler</h2>
  110. <p>Sometimes you may want to define global key handling logic for your entire
  111. application that is invoked regardless of what Window/View has focus. This can
  112. be achieved by using the <code>Application.RootKeyEvent</code> event.</p>
  113. </article>
  114. </div>
  115. <div class="hidden-sm col-md-2" role="complementary">
  116. <div class="sideaffix">
  117. <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
  118. <h5>In This Article</h5>
  119. <div></div>
  120. </nav>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. <footer>
  126. <div class="grad-bottom"></div>
  127. <div class="footer">
  128. <div class="container">
  129. <span class="pull-right">
  130. <a href="#top">Back to top</a>
  131. </span>
  132. <span>Generated by <strong>DocFX</strong></span>
  133. </div>
  134. </div>
  135. </footer>
  136. </div>
  137. <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
  138. <script type="text/javascript" src="../styles/docfx.js"></script>
  139. <script type="text/javascript" src="../styles/main.js"></script>
  140. </body>
  141. </html>