title: Implement close function on keypress in c++ builder
body: <p>How do I implement Close (or exit) function when the <kbd>ESC</kbd> key is pressed in a form application in C++ builder?</p>
  
  <p>Also, note that the form will have a number of components; it can't be only an empty form.
  I tried to use this code but it doesn't work every time I press <kbd>ESC</kbd>.</p>
  
  <pre><code>void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &amp;Key) {
  if (Key == VK_ESCAPE) {
      this-&gt;Close();
  }}
  </code></pre>
  
  <p>The code above doesn't work because focus is not always on the form and, if you have more components like EditBox, you have to disable <code>VK_ESCAPE</code> on every event and reference the desired function (which is, of course, a weak solution).</p>