How To…Prevent Beep on ESC

Question

“How do I prevent my computer from beeping when I press the ESC button in the preview?”

Solution

Create a preview plugin that overrides the KeyDown event.  Inside this event, check for the escape key press and change it preventing the default beep.

Download: NoBeepOnESC.zip

Sample Delphi code:

  TMyPreviewPlugin = class(TppPreview)
    private

    protected
      procedure KeyPressEvent(Sender: TObject; var Key: Char); override;

    public
      constructor Create(aOwner: TComponent); override;

   end;

implementation


procedure TMyPreviewPlugin.KeyPressEvent(Sender: TObject; var Key: Char);
begin
  inherited;

  if (Key = #27) then  //If the key pressed is ESC, change it.
    Key := #0;

end;


initialization
  TppPreviewPlugIn.Register(TMyPreviewPlugin);

finalization
  TppPreviewPlugIn.UnRegister(TMyPreviewPlugin);

  
end.