Re: Keyboard Event



On Sat, 11 Jun 2005 14:10:40 +0200, "Sander Martens"
<koningsander@xxxxxxx> wrote:

>Sometimes it takes so long to find such a simple solution.

The thick plottens :-}

I think I shall preempt your next question.

unit Unit1;

// Info from M.H. Avegaart
interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1KeyDown(Sender: TObject; var Key: Word;Shift:
TShiftState);
private
{ Private declarations }
public
end;

type
TMyButton = class(TButton)
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message
wm_GetDlgCode;
end;


var
Form1: TForm1;

implementation

{$R *.DFM}


procedure TMyButton.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
Msg.Result := DLGC_WANTARROWS or DLGC_WANTTAB or DLGC_WANTALLKEYS;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
B1,B2: TButton;
begin

B1 := TMyButton.Create(Self);
B1.SetBounds(8, 8, 75, 25);
B1.Parent := Self;
B1.OnKeyDown := Button1KeyDown;

B2 := TMyButton.Create(Self);
B2.SetBounds(8, 43, 75, 25);
B2.Parent := Self;
B2.OnKeyDown := Button1KeyDown;

end;


procedure TForm1.Button1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
(Sender as TButton).Caption := IntToStr(Key);
end;

end.

.


Quantcast