keyboard.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.4.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. <link href="https://fonts.googleapis.com/css?family=Source Sans Pro" rel="stylesheet">
  16. <link href="https://fonts.googleapis.com/css?family=Source Code Pro" rel="stylesheet">
  17. <meta property="docfx:navrel" content="../toc.html">
  18. <meta property="docfx:tocrel" content="../toc.html">
  19. <meta property="docfx:rel" content="../">
  20. </head> <body data-spy="scroll" data-target="#affix" data-offset="120">
  21. <div id="wrapper">
  22. <header>
  23. <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
  24. <div class="container">
  25. <div class="navbar-header">
  26. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
  27. <span class="sr-only">Toggle navigation</span>
  28. <span class="icon-bar"></span>
  29. <span class="icon-bar"></span>
  30. <span class="icon-bar"></span>
  31. </button>
  32. <a class="navbar-brand" href="../index.html">
  33. <img id="logo" class="svg" src="../images/logo48.png" alt="">
  34. </a>
  35. </div>
  36. <div class="collapse navbar-collapse" id="navbar">
  37. <form class="navbar-form navbar-right" role="search" id="search">
  38. <div class="form-group">
  39. <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
  40. </div>
  41. </form>
  42. </div>
  43. </div>
  44. </nav>
  45. <div class="subnav navbar navbar-default">
  46. <div class="container hide-when-search" id="breadcrumb">
  47. <ul class="breadcrumb">
  48. <li></li>
  49. </ul>
  50. </div>
  51. </div>
  52. </header>
  53. <div class="container body-content">
  54. <div id="search-results">
  55. <div class="search-list">Search Results for <span></span></div>
  56. <div class="sr-items">
  57. <p><i class="glyphicon glyphicon-refresh index-loading"></i></p>
  58. </div>
  59. <ul id="pagination" data-first="First" data-prev="Previous" data-next="Next" data-last="Last"></ul>
  60. </div>
  61. </div>
  62. <div role="main" class="container body-content hide-when-search">
  63. <div class="article row grid">
  64. <div class="col-md-10">
  65. <article class="content wrap" id="_content" data-uid="">
  66. <h1 id="keyboard-event-processing">Keyboard Event Processing</h1>
  67. <p><strong>Terminal.Gui</strong> respects common Linux, Mac, and Windows keyboard idioms. For example, clipboard operations use the familiar <code>Control/Command-C, X, V</code> model. <code>CTRL-Q</code> is used for exiting views (and apps).</p>
  68. <p>The input handling of <strong>Terminal.Gui</strong> is similar in some ways to Emacs and the Midnight Commander, so you can expect some of the special key combinations to be active.</p>
  69. <p>The key <code>ESC</code> can act as an Alt modifier (or Meta in Emacs parlance), to allow input on terminals that do not have an alt key. So to produce the sequence <code>Alt-F</code>, you can press either <code>Alt-F</code>, or <code>ESC</code> followed by the key <code>F</code>.</p>
  70. <p>To enter the key <code>ESC</code>, you can either press <code>ESC</code> and wait 100 milliseconds, or you can press <code>ESC</code> twice.</p>
  71. <p><code>ESC-0</code>, and <code>ESC-1</code> through <code>ESC-9</code> have a special meaning, they map to <code>F10</code>, and <code>F1</code> to <code>F9</code> respectively.</p>
  72. <p>Apps can change key bindings using the <code>AddKeyBinding</code> API. </p>
  73. <p>Keyboard events are sent by the <a href="mainloop.html">Main Loop</a> to the
  74. Application class for processing. The keyboard events are sent
  75. exclusively to the current <code>Toplevel</code>, this being either the default
  76. that is created when you call <code>Application.Init</code>, or one that you
  77. created an passed to <code>Application.Run(Toplevel)</code>. </p>
  78. <h2 id="flow">Flow</h2>
  79. <p>Keystrokes are first processes as hotkeys, then as regular keys, and
  80. there is a final cold post-processing event that is invoked if no view
  81. processed the key.</p>
  82. <h2 id="hotkey-processing">HotKey Processing</h2>
  83. <p>Events are first send to all views as a &quot;HotKey&quot;, this means that the
  84. <code>View.ProcessHotKey</code> method is invoked on the current toplevel, which
  85. in turns propagates this to all the views in the hierarchy. If any
  86. view decides to process the event, no further processing takes place.</p>
  87. <p>This is how hotkeys for buttons are implemented. For example, the
  88. keystroke &quot;Alt-A&quot; is handled by Buttons that have a hot-letter &quot;A&quot; to
  89. activate the button.</p>
  90. <h2 id="regular-processing">Regular Processing</h2>
  91. <p>Unlike the hotkey processing, the regular processing is only sent to
  92. the currently focused view in the focus chain.</p>
  93. <p>The regular key processing is only invoked if no hotkey was caught.</p>
  94. <h2 id="cold-key-processing">Cold-key Processing</h2>
  95. <p>This stage only is executed if the focused view did not process the
  96. event, and is broadcast to all the views in the Toplevel.</p>
  97. <p>This method can be overwritten by views that want to provide
  98. accelerator functionality (Alt-key for example), but without
  99. interfering with normal ProcessKey behavior.</p>
  100. <h2 id="key-bindings">Key Bindings</h2>
  101. <p><strong>Terminal.Gui</strong> supports rebinding keys. For example the default key
  102. for activating a button is Enter. You can change this using the
  103. <code>ClearKeybinding</code> and <code>AddKeybinding</code> methods:</p>
  104. <pre><code class="lang-csharp">var btn = new Button (&quot;Press Me&quot;);
  105. btn.ClearKeybinding (Command.Accept);
  106. btn.AddKeyBinding (Key.b, Command.Accept);
  107. </code></pre><p>The <code>Command</code> enum lists generic operations that are implemented by views.
  108. For example <code>Command.Accept</code> in a Button results in the <code>Clicked</code> event
  109. firing while in <code>TableView</code> it is bound to <code>CellActivated</code>. Not all commands
  110. are implemented by all views (e.g. you cannot scroll in a Button). To see
  111. which commands are implemented by a View you can use the <code>GetSupportedCommands()</code>
  112. method.</p>
  113. <p>Not all controls have the same key bound for a given command, for example
  114. <code>Command.Accept</code> defaults to <code>Key.Enter</code> in a <code>Button</code> but defaults to <code>Key.Space</code>
  115. in <code>RadioGroup</code>.</p>
  116. <h2 id="global-key-handler">Global Key Handler</h2>
  117. <p>Sometimes you may want to define global key handling logic for your entire
  118. application that is invoked regardless of what Window/View has focus. This can
  119. be achieved by using the <code>Application.RootKeyEvent</code> event.</p>
  120. </article>
  121. </div>
  122. <div class="hidden-sm col-md-2" role="complementary">
  123. <div class="sideaffix">
  124. <div class="contribution">
  125. <ul class="nav">
  126. <li>
  127. <a href="https://github.com/gui-cs/Terminal.Gui/blob/develop/docfx/articles/keyboard.md/#L1" class="contribution-link">Improve this Doc</a>
  128. </li>
  129. </ul>
  130. </div>
  131. <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
  132. <h5>In This Article</h5>
  133. <div></div>
  134. </nav>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <footer>
  140. <div class="grad-bottom"></div>
  141. <div class="footer">
  142. <div class="container">
  143. <span class="pull-right">
  144. <a href="#top">Back to top</a>
  145. </span>
  146. <span>Generated by <strong>DocFX</strong></span>
  147. </div>
  148. </div>
  149. </footer>
  150. </div>
  151. <script type="text/javascript" src="../styles/docfx.vendor.js"></script>
  152. <script type="text/javascript" src="../styles/docfx.js"></script>
  153. <script type="text/javascript" src="../styles/main.js"></script>
  154. </body>
  155. </html>