var
ImagePosX, ImagePosY: integer;
const
verschieben= 5;
//je größer um so schneller verschieben
procedure TForm1.FormCreate(Sender: TObject);
begin
ImagePosX:= Image1.Left;
ImagePosY:= Image1.Top;
Image1.Parent.DoubleBuffered:= true;
Timer1.Interval:= 100;
Timer1.Enabled:= false;
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if Timer1.Enabled= false
then
Timer1.Enabled:= true;
//Timer1Timer(Sender);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if GetAsyncKeyState(VK_LEFT)< 0
then
begin
dec(ImagePosX, verschieben);
Image1.Left:= ImagePosX;
end;
if GetAsyncKeyState(VK_RIGHT)< 0
then
begin
inc(ImagePosX, verschieben);
Image1.Left:= ImagePosX;
end;
if GetAsyncKeyState(VK_UP)< 0
then
begin
dec(ImagePosY, verschieben);
Image1.Top:= ImagePosY;
end;
if GetAsyncKeyState(VK_DOWN)< 0
then
begin
inc(ImagePosY, verschieben);
Image1.Top:= ImagePosY;
end;
end;
procedure TForm1.FormKeyUp(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
Timer1.Enabled:= false;
end;