Mirror

How to simulate a PrintScreen key press (Views: 709)


Problem/Question/Abstract:

How can I manually call the "hardcopy" function (PrtScr) or how can I trick it by sending the keycode for PrtScr?

Answer:

procedure SimulateKeystroke(Key: byte; extra: DWORD);
begin
  keybd_event(Key, extra, 0, 0);
  keybd_event(Key, extra, KEYEVENTF_KEYUP, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  {Capture the entire screen to the clipboard by simulating pressing the PrintScreen key}
  SimulateKeystroke(VK_SNAPSHOT, 0);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  {Capture the active window to the clipboard by simulating pressing the PrintScreen key}
  SimulateKeystroke(VK_SNAPSHOT, 1);
end;

<< Back to main page