Board index » delphi » Intercepting The Enter Key

Intercepting The Enter Key

I have a form where I intercept the ENTER key, and make it go to the next
control. This works fine.  Now, I want to implement it on another form, but
I can't figure out how.  I've put this code in the form, but it doesn't
execute:
procedure TLoginForm.LoginNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
    begin
      Key:=#0;
      Perform(wm_NextDlgCtl,0,0);
    end;
end;

I haven't found any notable differences between the forms.  Is there a
setting I need to change in order to be able to intercept the key?

Thanks,
Jesse

 

Re:Intercepting The Enter Key


Jesse,
  Do you have the KeyPreview property for the form set to True ?

Hope this helps!
--

Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Jesse Castleberry <D...@iThink.net> wrote in article
<BSsZ1.908$Qf3.2...@news9.ispnews.com>...

Quote
> I have a form where I intercept the ENTER key, and make it go to the next
> control. This works fine.  Now, I want to implement it on another form,
but
> I can't figure out how.  I've put this code in the form, but it doesn't
> execute:
> procedure TLoginForm.LoginNameKeyPress(Sender: TObject; var Key: Char);
> begin
>   if Key=#13 then
>     begin
>       Key:=#0;
>       Perform(wm_NextDlgCtl,0,0);
>     end;
> end;

> I haven't found any notable differences between the forms.  Is there a
> setting I need to change in order to be able to intercept the key?

> Thanks,
> Jesse

Re:Intercepting The Enter Key


Quote
Jesse Castleberry wrote in message ...
>I have a form where I intercept the ENTER key, and make it go to the next
>control. This works fine.  Now, I want to implement it on another form, but
>I can't figure out how.  I've put this code in the form, but it doesn't
>execute:
>procedure TLoginForm.LoginNameKeyPress(Sender: TObject; var Key: Char);
>begin
>  if Key=#13 then
>    begin
>      Key:=#0;
>      Perform(wm_NextDlgCtl,0,0);
>    end;
>end;

>I haven't found any notable differences between the forms.  Is there a
>setting I need to change in order to be able to intercept the key?

Did you remember to set TLoginForm.KeyPreview to True?
--
Garry Knight
Computer programmer, psychotherapist, writer
ga...@garryknight.freeserve.co.uk

Re:Intercepting The Enter Key


In article <BSsZ1.908$Qf3.2...@news9.ispnews.com>, "Jesse Castleberry"

Quote
<D...@iThink.net> writes:
>Is there a
>setting I need to change in order to be able to intercept the key?

Have you got form's KeyPreview set to true?

Charles Johnson

Re:Intercepting The Enter Key


Quote
>Did you remember to set TLoginForm.KeyPreview to True?

Well, on my TLoginForm, it's not set to True, and it still works.  I found
the problem.  I had a button set to "Default", so when I pressed the enter
key, it was intercepting it.   When I set Default to True, then I was able
to process the enter key.

Jesse

Re:Intercepting The Enter Key


Quote
>  Do you have the KeyPreview property for the form set to True ?

on my original LoginForm, I didn't have it set to True, but it still worked.
I found the problem.  I had a button set to "Default", so when I pressed the
enter key, it was intercepting it.   When I set Default to True, then I was
able to process the enter key.

Other Threads