using the arrow keys

Please discuss general Delphi programming topics here.

using the arrow keys

Postby stowaway » March 9th, 2009, 11:03 am

Hello,
Im very new to delphi programming..
I had moderate experience with turbo pascal in my high school days, but nothing extreme.

Im trying to run my RC car through my computer.. any how i want to use the Arrow keys. Ive got to the point where I can detect keydown VK_UP (VK_DOWN ect) but i have to hold the ALT key for it to work...
Also I want to be able to detect if 2 keys are pressed (ie UP AND LEFT) heres what ive got so far:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
VK_LEFT: label1.Caption := 'This is Left Key';
VK_UP : label1.Caption := 'This is the up key';
end;
end;
stowaway
Member
Member
 
Posts: 1
Joined: March 9th, 2009, 10:49 am

Re: using the arrow keys

Postby Kambiz » March 9th, 2009, 11:45 am

You may want to consider using this function inside a timer.

Code: Select all
function IsKeyDown(VirtualKey: Integer): Boolean;
begin
  Result := WordBool(GetKeyState(VirtualKey) and $8000);
end;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 5 guests

cron