Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to handle Navigation keys (Tab, arrow keys) with OnKeyDown ?

Status
Not open for further replies.

swim

Programmer
Jul 1, 2002
22
US
I know that navigation keys (Tab, BackTab, the arrow keys, and so on) are unaffected by KeyPreview because they do not generate keyboard events.

But I really want to handle Navigation keys with OnKeyDown event.

I added the codes as follows, but it still does not work:

procedure WMGetDlgCode(var Message : TWMGetDlgCode); message WM_GETDLGCode;

// Let the control see the arrow keys and the tab key
procedure TTVDGLEdit.WMGetDlgCode(var Message : TWMGETDLGCODE);
begin
Message.Result := Message.Result + DLGC_WANTARROWS + DLGC_WANTTAB;
end;

Thanks for any advice.
 
Isn't this what you're after?

Code:
[b]procedure[/b] TForm1.FormKeyDown(Sender: TObject; [b]var[/b] Key: Word;
  Shift: TShiftState);
[b]begin[/b]
  [b]if[/b] Key = VK_DOWN [b]then[/b]
  [b]begin[/b]
    [navy][i]// handle down arrow
[/i][/navy]  [b]end[/b];
[b]end[/b];
 
Yes, I did.
But the down arrow key doesn't fire the onkeydown event.
 
It works for me when I set the Form's KeyPreview property to True
 
note: it wont work if particular components has the focus, for example TButton.

Aaron
 
Thank aaronjme.

I used TRadioButton which will has focus when be selected. That is the reason what happened.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top