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

Enter key or Return key?

By Zarko Gajic, About.com Guide

Here's how to differentiate between the user pressing the ENTER (return) key on the standard keyboard and the ENTER key on the numeric keypad.

~~~~~~~~~~~~~~~~~~~~~~~~~
interface
... private
procedure WMKeyDown(var Message: TWMKeyDown) ; message CM_DIALOGKEY;

implementation
...
procedure TForm1.WMKeyDown(var Message: TWMKeyDown) ;
begin
   inherited;
   case Message.CharCode of
     VK_RETURN: // ENTER pressed
       if (Message.KeyData and $1000000 <> 0) then
         // Test bit 24 of lParam
         ShowMessage('ENTER on numeric keypad')
       else
         ShowMessage('ENTER on Standard keyboard') ;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» How to load HTML directly to a WebBrowser
« How to place a progress bar inside a standard dialog box

Explore Delphi Programming
About.com Special Features

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

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. Enter key or Return key?

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

All rights reserved.