This site is temporarily down. Please come back. Arrow keys do not generate WM_KEYDOWN
DelphiFAQ Home Search:

Arrow keys do not generate WM_KEYDOWN

 

comments2 comments. Current rating: 5 stars (2 votes). Leave comments and/ or rate it.

Problem:
The KEYDOWN event does not get fired for the left/right arrow keys.
When placed on a form with more than one other control, the left and right arrow keys move the focus, instead of firing an event.

Solution:
You need to handle WM_GETDLGCODE to tell Windows what keyboard messages you want to process.


// based on a contribution from David Rifkind <drifkind@acm.org>
type
  TMyControl = class(TWinControl)
  private
    //..
    procedure WMGetDlgCode(var message: TMessage);
      message WM_GETDLGCODE;
    //..
  end;

// request the arrow keys + characters
procedure TMyControl.WMGetDlgCode(var message: TMessage);
begin
  message.Result := DLGC_WANTARROWS or DLGC_WANTCHARS;
end;

Content-type: text/html

Comments:

2007-01-19, 02:44:33
anonymous from Austria  
rating
2007-04-17, 06:06:15
anonymous from France  
rating
Very good tips ! helpful for Visual C++ MFC too !!

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: