unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
x,y,Breite, Hoehe,i, z: Integer;
oben, unten: Boolean;
Quelle, Ziel: TRect;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
x := 30;
y := 180;
Breite := 15;
Hoehe := 100;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_Space then
begin
Canvas.Brush.Color := clGreen;
Canvas.Rectangle(x,y,x+Breite,y+Hoehe);
end;
if key = vk_Up then
begin
oben := true;
end;
if key = vk_Down then
unten := true;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_Up then
oben := false;
if key = vk_Down then
unten := false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if oben then
begin
Canvas.Rectangle(x,y-10,x+Breite,y+Hoehe-10);
end;
if unten then
begin
Canvas.Rectangle(x,y+10,x+Breite,y+Hoehe+10);
end;
end;
end.