How To…Add Preview Hot Key Support

Question

“How do I add hot key support to the preview window?  For instance pressing F8 prints the report?”

Solution

Create a preview plugin that overrides the KeyDown routine.  From there you can capture any key presses and perform any task you need.

Download: HotKeyPrintPlugin.zip

Sample Delphi code:

type
  TmyHotKeyPrint = class(TppPreview)
    public
      procedure KeyDown(var Key: Word; Shift: TShiftState); override;

  end;

implementation

{ TmyHotKeyPrint }

procedure TmyHotKeyPrint.KeyDown(var Key: Word; Shift: TShiftState);
begin

  inherited KeyDown(Key, Shift);

  if (Shift = []) and (Key = VK_F8) then
    Print;

end;

initialization
  TppPreviewPlugIn.Register(TmyHotKeyPrint);

finalization
  TppPreviewPlugIn.UnRegister(TmyHotKeyPrint);


end.