Danke für eure Antworten, ich habs jetzt folgendermaßen gelöst:
Delphi-Quellcode:
type
TForm1 = class(TForm)
Pn1: TPanel;
Pn2: TPanel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
KeyW, KeyS, KeyU, KeyD: Boolean;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if KeyW = True then
begin
Pn1.Top := Pn1.Top - 5;
end;
if KeyS = True then
begin
Pn1.Top := Pn1.Top + 5;
end;
if KeyU = True then
begin
Pn2.Top := Pn2.Top - 5;
end;
if KeyD = True then
begin
Pn2.Top := Pn2.Top + 5;
end;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = $57 then
begin
KeyW := True;
end;
if Key = $53 then
begin
KeyS := True;
end;
if Key = $26 then
begin
KeyU := True;
end;
if Key = $28 then
begin
KeyD := True;
end;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = $57 then
begin
KeyW := False;
end;
if Key = $53 then
begin
KeyS := False;
end;
if Key = $26 then
begin
KeyU := False;
end;
if Key = $28 then
begin
KeyD := False;
end;
end;
end.