Board index » delphi » catching enter-key in TEdit.OnKeyDown ?

catching enter-key in TEdit.OnKeyDown ?

I have an Edit on a form and when I try to catch the enter-key, it won't
work. Setting a breakpoint tells me that the onkeydown event isn't even
triggered, so I can never compare the Key parameter with VK_RETURN.

I tried a empty application with an edit and using the same code and it
works perfectly. I seems I have changed something, that prevents the enter
key from triggering  the onkeydown event. To be more precise I have the edit
on a page of a Tpagecontrol, but this shouldn't be of importance, or is it?

Thanks in advance,

Peter Schram

P.S. Merry Christmas to everyone!

 

Re:catching enter-key in TEdit.OnKeyDown ?


Quote
"Peter Schram" <psch...@casema.net> wrote in message

news:922lr5$qvi6@bornews.inprise.com...
Quote
> I have an Edit on a form and when I try to catch the enter-key, it won't
> work. Setting a breakpoint tells me that the onkeydown event isn't even
> triggered, so I can never compare the Key parameter with VK_RETURN.

> I tried a empty application with an edit and using the same code and it
> works perfectly. I seems I have changed something, that prevents the enter
> key from triggering  the onkeydown event. To be more precise I have the
edit
> on a page of a Tpagecontrol, but this shouldn't be of importance, or is

it?

try setting MainForm.KeyPreview to True

--
Windows Multitasking - screwing up several things at once
Make it right before you make it faster.
ICQ: 91418899
http://www.planeted.co.uk
http://members.nbci.com/edduffe

Re:catching enter-key in TEdit.OnKeyDown ?


Peter

Quote
> I have an Edit on a form and when I try to catch the enter-key, it won't
> work. Setting a breakpoint tells me that the onkeydown event isn't even
> triggered, so I can never compare the Key parameter with VK_RETURN.

It appears that something else on your form is intercepting the message,
especially if it works on the "empty" application you describe.  You can try
an event handler on the parent objects.  If that works at some point (say at
the TForm level) then you know that the message was dispatched to another
object.

One thing you might look for is whether you have a button control like a
TButton on the form and its Default property is set to True.  This will
respond to VK_RETURN as the default action.

Joe

Re:catching enter-key in TEdit.OnKeyDown ?


procedure TForm1.editKeyPress(Sender: TObject; var Key: Char);
if key=#13 then
begin
     key:=#0;
     // have som fun
end;

"J. M. De Moor" <jmdem...@nospamobjectpac.com> skrev i meddelandet
news:9234g6$ngd7@bornews.inprise.com...

Quote
> Peter

> > I have an Edit on a form and when I try to catch the enter-key, it won't
> > work. Setting a breakpoint tells me that the onkeydown event isn't even
> > triggered, so I can never compare the Key parameter with VK_RETURN.

> It appears that something else on your form is intercepting the message,
> especially if it works on the "empty" application you describe.  You can
try
> an event handler on the parent objects.  If that works at some point (say
at
> the TForm level) then you know that the message was dispatched to another
> object.

> One thing you might look for is whether you have a button control like a
> TButton on the form and its Default property is set to True.  This will
> respond to VK_RETURN as the default action.

> Joe

Re:catching enter-key in TEdit.OnKeyDown ?


Quote
> procedure TForm1.editKeyPress(Sender: TObject; var Key: Char);
> if key=#13 then
> begin
>      key:=#0;
>      // have som fun
> end;

I don't think this code will compile without a procedure enclosing
begin-end;

Joe

Other Threads