be sure to set keypreview to true;
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: char);
private
{ private declarations }
public
Timer:Integer;
Procedure TimeOut;
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Timeout;
end;
procedure TForm1.FormKeyPress(Sender: TObject; var Key: char);
begin
Timer:=0;
end;
Procedure TForm1.TimeOut;
begin
Timer:=30; //set the timer to 30 sec
while Timer>0 do
begin
//your code here
Form1.Caption:='Timer:'+IntToStr(Timer);
Application.ProcessMessages; //allow events to be processed
Sleep(1000); //sleep for one sec
Dec(Timer);
end;
Form1.Caption:='Time out finished';
end;
end.