这是函数: procedure TMainForm.Detect(var Msg: TMsg; var Handled: boolean); begin if (Msg.message<>WM_KEYDOWN) or (Msg.message<>WM_MOUSEMOVE) then begin application.MainForm.Show end end;调用: procedure TMainForm.Timer1Timer(Sender: TObject); begin Application.OnMessage:=Detect; end; 但不能把TMainForm变为当前窗口。
function LastInput: DWord; var LInput: TLastInputInfo; begin LInput.cbSize := SizeOf(TLastInputInfo); GetLastInputInfo(LInput); Result := GetTickCount - LInput.dwTime; end; //Example: procedure TForm1.Timer1Timer(Sender: TObject); begin Label1.Caption := Format('System Idle since %d ms', [LastInput]); end;那就可以判断空闲时间有多长的http://lysoft.7u7.net
搜一下SetWindowsHook, UnhookWindowsHook网上有好多例子
1、public里加: procedure WndProc(var Msg: TMessage); override;2、var Form1: TForm1; TimeCount:integer;//秒3、procedure TForm1.WndProc(var Msg: TMessage); begin inherited; if (Msg.MSG=WM_MOUSEMOVE) or (Msg.MSG=WM_LBUTTONDOWN) or (Msg.MSG=WM_RBUTTONDOWN) or (Msg.MSG=WM_KEYDOWN) Then timeCount:=0; end;procedure TForm1.Timer1Timer(Sender: TObject); begin inc(timeCount); if timecount=20 then begin //你要执行的语句; end; end;OK了……
to:ly_liuyang(Liu Yang) 写的很好,但达不到我的要求 不过,还是谢谢你!
TO: kkgogo(kkgogo) procedure TForm1.Timer1Timer(Sender: TObject); begin inc(timeCount); if timecount=20 then begin //你要执行的语句;????这句关键 end; end;
if timecount=20 then begin Application.CreateForm(TForm2, Form2); Form2.ShowModal; end;这种?
procedure TMainForm.Detect(var Msg: TMsg; var Handled: boolean);
begin
if (Msg.message<>WM_KEYDOWN) or (Msg.message<>WM_MOUSEMOVE) then
begin
application.MainForm.Show
end
end;调用:
procedure TMainForm.Timer1Timer(Sender: TObject);
begin
Application.OnMessage:=Detect;
end; 但不能把TMainForm变为当前窗口。
var
LInput: TLastInputInfo;
begin
LInput.cbSize := SizeOf(TLastInputInfo);
GetLastInputInfo(LInput);
Result := GetTickCount - LInput.dwTime;
end;
//Example:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := Format('System Idle since %d ms', [LastInput]);
end;那就可以判断空闲时间有多长的http://lysoft.7u7.net
procedure WndProc(var Msg: TMessage); override;2、var
Form1: TForm1;
TimeCount:integer;//秒3、procedure TForm1.WndProc(var Msg: TMessage);
begin
inherited;
if (Msg.MSG=WM_MOUSEMOVE) or
(Msg.MSG=WM_LBUTTONDOWN) or
(Msg.MSG=WM_RBUTTONDOWN) or
(Msg.MSG=WM_KEYDOWN) Then
timeCount:=0;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(timeCount);
if timecount=20 then
begin
//你要执行的语句;
end;
end;OK了……
写的很好,但达不到我的要求
不过,还是谢谢你!
procedure TForm1.Timer1Timer(Sender: TObject);
begin
inc(timeCount);
if timecount=20 then
begin
//你要执行的语句;????这句关键
end;
end;
begin
Application.CreateForm(TForm2, Form2);
Form2.ShowModal;
end;这种?
Form:=TForm.Create(self);
Form.Show;
如果窗口已经存在,显示就是了
不是Show或ShowModal,而是让那个窗口激活
比如:我的程序运行着的,同时我在打开网页,过一段时间没有键盘鼠标动作后原先程序主窗口自动成为屏幕窗口。
你试试;