1. Home
  2. Computing & Technology
  3. Delphi Programming

Close your application with the ESC key

By , About.com Guide

Make sure that you set the KeyPreview property of the Form to True. This will make keyboard events occur on the form, before the active control. You should set this in the create event of the form. Below, you will find a code sample that demonstates how to do this.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.FormCreate(Sender: TObject) ;
begin
   KeyPreview := True;
end;

procedure TForm1.FormKeyPress
   (Sender: TObject; var Key: Char) ;
begin
   if key = #27 then Close;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to get the filename of the process that is currently executing
« How to Refresh the Desktop window

Explore Delphi Programming
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. Close your application with the ESC key

©2010 About.com, a part of The New York Times Company.

All rights reserved.