Link to home
Start Free TrialLog in
Avatar of logosapience
logosapience

asked on

VK_UP & VK_DOWN

Hello,

I want to do something in my app when the user presses the Up or Down arrow, so I wrote my code on the FormKeyDown event (with KeyPreview = true).
 
The problem is the following : the event doesn't happen when the up or down arrow is pressed but happen if any other key is pressed.

What can I do?
ASKER CERTIFIED SOLUTION
Avatar of Lischke
Lischke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of christha
christha


This code moves a label up or down
when the up/down arrow-key is pressed.

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

if key = 38 then begin   // up
  label1.top:=label1.top - 5;
end
else if key = 40 then begin   // down
    label1.top:=label1.top + 5;
end;
end;

Avatar of logosapience

ASKER

The problem is that the formKeyDown does not happen...
I agree with Mike :O)

Sounds like some other control is eating your messages...

Not much help, I know...soz...

Tim.
christha, PLEASE, read the question first and post comments instead of answers unless you are totally sure the questioneer wants your contribution as answer! Thank you.

logosapience, you replied to christha but not to me. Don't you believe me or did it make you struck all of a heap ;-)?

 
Ciao, Mike
would this help:

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    Procedure CMDialogKey( Var msg: TCMDialogKey );
      message CM_DIALOGKEY;
 

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

Procedure TForm1.CMDialogkey;
Begin
    Case msg.charcode of
               vk_Down:
                       showmessage('key down pressed');
                 vk_Up:
                       showmessage('key up pressed');
     else
     inherited;
    End;
  End;

Regards Barry
Thanks, it works...
Oh is it really so easy? I'm ashamed :-/ Looks as if there's another "call back" path for keyboard input I haven't seen yet.

Thank you and

Ciao, Mike
Finalized today by Moondancer - EE Moderator
Hey!
  inthe's code works!
  Wonder why his answer wasn't accepted.
  ne way, thanks inthe. Can you explain what TCMDialogKey is?
...Shu
NM,
  A similar question has been asked recently, and while searching for an answer, I found this Q and found it interesting that a good answer was not accepted.
  If inthe is active, he can comment at:
https://www.experts-exchange.com/questions/20895615/TCheckBox-KeyDown.html
  But if he isn't , I was hoping that it was more likely that an email due to my comment would bring him here.
...Shu