OnKeyDown and arrow key pressed

Posted by Frankie on March 11, 2009

In Reply to Arrow Key Pressed posted by Stowaway on March 09, 2009

: Im trying to make an application that watches for the arrow key presses. Ive got it working but for some reason it only works when i hold the ALT key down.
: how can i get around this?

I tested your code and it works as it should. No need to press ALT.

In order to have no other stuff that could influence it, test it in a new project with a form with only Label1 and in the unit only the following TForm1.FormKeyDown procedure, so that you can see what is detected in the KeyDown:

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  Label1.Caption := IntToStr(Key) + ' ';
  case Key of
    VK_LEFT:  Label1.Caption := Label1.Caption + 'LEFT';
    VK_RIGHT: Label1.Caption := Label1.Caption + 'RIGHT';
    VK_UP :   Label1.Caption := Label1.Caption + 'UP';
    VK_DOWN:  Label1.Caption := Label1.Caption + 'DOWN';

Related articles


Follow Ups