Re:onKeyDown problem.
Quote
In article <3456118F.EAF6F...@pi.net>, Henk Hinssen wrote:
> I have a TForm with some buttons and a TPaintbox component. I need to
> catch in the TForm's onKeyDown eventhandler the VK_LEFT and VK_RIGHT.
> I set TForm's KeyPreview to TRUE, but it seems to me that thise virtual
> key's does not generate a exception. Houw can I catch thise key's?
YOu need to go to an application level message handler to trap them properly.
The following unit demonstrates with the VK_UP and VK_DOWN keys:
unit Arrows;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TFrmArrows = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
private { Private-Deklarationen }
procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
public { Public-Deklarationen }
end;
var
FrmArrows: TFrmArrows;
implementation
{$R *.DFM}
procedure TFrmArrows.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.Message = WM_KEYDOWN then
if Msg.wParam = VK_UP then begin
SelectNext(ActiveControl, false, true); { Move to previous control. }
//PostMessage(Handle, WM_NEXTDLGCTL, 1, 0);
Handled := true
end
else if Msg.wParam = VK_DOWN then begin
SelectNext(ActiveControl, true, true); { Move to next control. }
//PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
Handled := true;
end;
end;
procedure TFrmArrows.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;
end.
Regards
Ralph (TeamB)
Herrsching, Germany, Tue, 28 Oct 1997 18:01 +0100 CET