Question and Answer Database FAQ930D.txt Detecting if the PrintScreen key has been pressed Category :Windows API Platform :All Product :All 32 bit Question: How can I tell if the PrintScreen key has been pressed? Answer: The PrintScreen system key is not processed during the TForm keydown event. The following example tests if the PrintScreen key has been pressed by calling the Windows API function GetAsyncKeyState() during the Application.OnIdle event. Example: type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } procedure AppIdle(Sender: TObject; var Done: Boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin Application.OnIdle := AppIdle; end; procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean); begin if GetAsyncKeyState(VK_SNAPSHOT) <> 0 then Form1.Caption := 'SnapShot'; Done := True; end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99