Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Catching the return key within a form
Fri, Nov 3 2017 4:55 PMPermanent Link

Richard Mace

Hi,

I am wanting to detect the return key so that I can assume that the user wants to effectively press the OK button on a form.

What's the best way of doing this?

Thanks
Sun, Nov 5 2017 4:58 PMPermanent Link

Howard Chandler

Fiscalsoft Corporation

Richard,

> I am wanting to detect the return key so that I can assume that the user wants to effectively press the OK button on a form.
>
> What's the best way of doing this?

You can use the form's OnKeyPress event:

function TFrmMainForm.FrmMainFormKeyPress(Sender: TObject; Key: Char;
ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
begin
 if (Key = #13) then
  OKButtonClick(Self);
end;

Howard
Sun, Nov 5 2017 6:40 PMPermanent Link

Howard Chandler

Fiscalsoft Corporation

Richard,
>
>> I am wanting to detect the return key so that I can assume that the
>> user wants to effectively press the OK button on a form.
>>
>> What's the best way of doing this?
>
> You can use the form's OnKeyPress event:
>
> function TFrmMainForm.FrmMainFormKeyPress(Sender: TObject; Key: Char;
> ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
> begin
>  if (Key = #13) then
>   OKButtonClick(Self);
> end;
>
> Howard

Sorry, it's a function in EWB so we need to include a Result:

function TFrmMainForm.FrmMainFormKeyPress(Sender: TObject; Key: Char;
ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
begin
 if (Key = #13) then
  OKButtonClick(Self);
 Result := True;
end;

Howard
Mon, Nov 6 2017 3:54 PMPermanent Link

Richard Mace

Chandler wrote:

<< Sorry, it's a function in EWB so we need to include a Result:

function TFrmMainForm.FrmMainFormKeyPress(Sender: TObject; Key: Char;
ShiftKey, CtrlKey, AltKey: Boolean): Boolean;
begin
 if (Key = #13) then
  OKButtonClick(Self);
 Result := True;
end;

Howard >>

Perfect, thanks howard.

Richard
Image