MikeD
MikeD

Reputation: 637

Firemonkey sound when pressing enter on OSX

Using Delphi XE8, Firemonkey multi-device form.

In a standard TEdit set up for a password input, I'm unable to stop the default alert sound when the user presses enter (on OSX), Windows works fine.

I've tried setting the following in the KeyDown and KeyUp events:

procedure TfrmMain.txtPasswordPromptKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if (Key = vkReturn) and (btnPasswordPromptGo.Tag = 0) then begin
    Key := vkNone;
    KeyChar := #0;
    btnPasswordPromptGoClick(sender);
  end;
end;

procedure TfrmMain.txtPasswordPromptKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if (Key = vkReturn) and (btnPasswordPromptGo.Tag = 0) then begin
    Key := vkNone;
    KeyChar := #0;
  end;
end;

The sound still plays on OSX. Does anyone know how to stop this?

Upvotes: 0

Views: 319

Answers (1)

Roy Woll
Roy Woll

Reputation: 322

Don't use vknone for your Key value, instead just set your result to 0. That should prevent the beep.

procedure TfrmMain.txtPasswordPromptKeyDown(Sender: TObject;
  var Key: Word; var KeyChar: Char; Shift: TShiftState);
begin
  if (Key = vkReturn) and (btnPasswordPromptGo.Tag = 0) then begin
    Key := 0;
  end;
end;

Also as Rob mentioned, you could set your Default property to true for the button you want executed when return is encountered. If you do this, you should not need the code that eats the carriage return.

Upvotes: 0

Related Questions