Boring sound when closing Form lazarus / 13-General ---------------------------------------------------------------------- mirce.vladimirov · 2011-06-25 12:07 I'm using windows XP, lazarus 0.9.30. Some of my forms are playing owful and boring sound when I press Escape on keyboard to close the form.  I usualy have one button on each form, and under it's OnClick event i just put simply Code: [Select]begin close; end; Why it is not happening with all of my forms ? What causes/prevents this ? I can't see the diference between the forms that play that sound and the ones that don't play it. P.S.I have found the sound under ControlPanel->SoundsAndAudiDevices->Sounds, it's called "Default Beep" and comes from WindowsXpDing.wav. ---------------------------------------------------------------------- mirce.vladimirov · 2011-06-25 12:13 I've just find out why it is happening: if the focus is on a TEdit, and I press ESC, then it plays this sound and closes the form, but if the focus is on a TComboBox or TDBGrid or TButton when I press ESC it doesnot plays that sound. Why does it plays it anyway, i dont want it ? ---------------------------------------------------------------------- fabienwang · 2011-06-25 13:50 instead of close, put Self.close; or Application.terminate; ---------------------------------------------------------------------- eny · 2011-06-25 14:48 Quote from: FabienWang on June 25, 2011, 03:50:05 pminstead of close, put Self.close; or Application.terminate; This is not the solution: these sounds are generated somewhere and it should be possible to disable them. When you create a modal dialog with standard actions buttons (Ok, Close, Cancel) then pressing the ESC button automatically closes the form and generates the annoying sound. ---------------------------------------------------------------------- mirce.vladimirov · 2011-06-25 16:33 Quote from: FabienWang on June 25, 2011, 03:50:05 pminstead of close, put Self.close; or Application.terminate; Tried self.close, stil plays the sound. Application.terminate is not wanted here, it will close the apllication, but i want to close only the current Form, not entire application. To open up a form i do Code: [Select]myform.showmodal ---------------------------------------------------------------------- ViRuSTriNiTy · 2013-12-11 10:44 The ESC keypress is forwarded to the edit control and it plays that sound because ESC is not a valid input action. Try it yourself, click on a TEdit to give it focus then press ESC, you will always hear the default bing sound of windows. So, closing the form without the sound is pretty simple as you just have to ensure that the keypress is not forwarded to TEdit: 1) set TForm.KeyPreview = true 2) add an OnKeyDown event handler with the following code Code: [Select]procedure TMyForm.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin   if Key = 27 then begin     Close();     Key := 0; // avoid forwarding of key stroke to focused control   end; end;