Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Timer1: TTimer;
- Label1: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- i:Integer = 0;
- hThread:THandle;
- tid:DWORD;
- suspended:Boolean = true;
- implementation
- {$R *.dfm}
- procedure Increasekkt;
- begin
- repeat
- Inc(i);
- Form1.Caption:=IntToStr(i);
- until 3=4;
- end;
- function GetIdleTime:DWORD;
- var
- last:TLastInputInfo;
- begin
- last.cbSize:=Sizeof(last);
- GetLastInputInfo(last);
- Result:=(GetTickCount - last.dwTime)div 1000;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- hThread:=CreateThread(nil,0,@Increasekkt,nil,CREATE_SUSPENDED,tid);
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- Label1.Caption:=IntToStr(GetIdleTime);
- if (GetIdleTime>5) and (Suspended) then
- begin
- ResumeThread(hThread);
- suspended:=false;
- end
- else if (GetIdleTime<5) and (not Suspended) then
- begin
- suspended:=true;
- SuspendThread(hThread);
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement